I have several questions regarding a client server model. My current application (or rather my proposed one) uses a central server and different clients can connect to it.
(Small explanation of O(n) for people wanting to answer the questions and not knowing about it, either google or follow this example:
Consider a list with n elements. O(1) means that you can just pick the element and O(n) basically means that you possibly have to iterate over every element (thus n elements) to get the item you want. And O(log n) is a middle way having to do with recursive subdivision which is still a lot faster as O(n) but not as fast as O(1).)
Question 1:
How can I efficiently retrieve records of users, I got no clue how many users the server will have to handle at some point, but I strongly believe that O(n) operations just will not suffice if O(1) is reasonble to implement.
First part is about the login procedure, I plan to let the user login with a personal identifier (username/email/etc.) and a password, this information gets sent to the server once someone tries to log in.
Furthermore I also plan to not use a database (for example MySQL) directly, but purely for 'backup' purposes (the server should store all information in RAM if possible, and only write it to the database such that nothing gets lost when power gets lost).
So basically the server needs to store the Client data (including the personal identifier, but also an unique ID).
My current ideas:
Store in a List, however then searching for a user (and then validate his information) may take O(n) time depending on the sorting, I could cut it down to O(log n) if I do something with alphabetical sorting on username.
Second proposal would be to store it in a Client[] array with the UniqueID's as keys. Then access in O(1) should be possible which is ideal, however the problem I am having with that approach is how do I convert the personal identifier (username, etc.) which the user puts in and sends to the server, to his unique ID? If I use anything like a List then the time will be O(n) again. Moreover, the array size may not be unproportionally huge, as it would simply allocate too much memory, for example I do not think that hashing the users name is ideal nor am I sure if it creates a unique ID.
Question 2:
Secondly I also want my userdata to be secure of course. Now assume that the underlying MySQL server (from which the data gets loaded into server's RAM at startup) is secure.
Then I wonder are the saved passwords (encrypted of course) also safe given these conditions?
Nothing has direct physical access to the server.
The communication protocol has no commands to retrieve password information or a superset including the password information, meaning that the server will under no conditions give out the password.
The passwords are stored as private variables in the Client objects that hang around in the server's RAM.
To check if the information a user has entered, is correct the Client object has a function like
client.confirmPassword(password)
.
So unless I have forgotten things, the question basically comes down to can the RAM of the Server be directly read given that it is only connected to the outside world via a communication protocol?
Post turned out to be pretty long, but I hope there are people around that can answer these questions :)