I have made a game that I now want to add a user account like system to it. I would like it to keep track of name, username, password, and wins but I'm having a hard time figuring out how to do all this.
The way I figure it I would have to do an output file to save it but how would I update the input file for the next time the program ran? Is there an easier way to make an account system?
So you want a way to manage account settings in a server, and allow changes to be made, even if the account is not loaded into memory?
This is not an server base. It a full c++ program run in terminal
Well, you most certainly can do it that way =D Lucky for you, there aren't really any limitations on implementation, it's all up to you!
If it were me, I'd probably come up with a simple protocol and encryption algorithm to save your data, and to read it in when it comes time.
Simplicity is key.
That sounds interesting but more complex then needed. I need a simple account system, no need for encryption as this is just a class room program.
basically right now i have predefined username and passwords in an input file they are read in and if player one is equals the first username and password then program runs, if it's two player then player 1 must enter first username and password and player 2 must enter the second username and password in the input file. This looks like it work but i'm still working the errors out.
Biggest con is that the user can't enter the second username and password because the file reads in the first one.
at the end the outputfile has username, password, and wins inside of it but this will be over written by the next time the program is used. Not sure if there is a way to write it back to the input file without deleting the other users.
Just load the entire file into an appropriate data structure (perhaps a std::map), then search for the username in that structure and check the password.
Write back all user records to the account file when the number of wins changes or an user is created/deleted.
1) Create a simple menu that allows any user to login, create a new accout, etc...
2) If a user chooses to login, take the username and password and store them into a buffer of some type.
3) Compare the username to a database( separate file ). If the username matches, compare the password.
4) If the users details are correct, load the save game file that is linked to that user.
5) If the user chose to create a new account, save the requested username and password to the database.
6) Create a new save game file and link it to the new account.
This is a rough outline, but I was thinking fast, so to speak.