Hi i finally got my variables to work I'm in beginning stages trying to make a game need to know how to save ID AND PASSWORD ENTERED BYE THE USER and retrieve it for later so they can log on its the basic beginning to any game here my code so far AND is c++ the best program trying to save dat
you don't have to output information which is not required. like User name: & password:
just write the real name and password. plain text will do at this stage.
the way you are writing, the same way you are going to read.. so each record will start with a new line. once, you write the name and password, write a new line.
when reading, you can use, ifstream and getline(). keep reading lines in std::string and extract name and password from each line.. you can do whatever you want..
1 2 3 4 5 6 7 8
ifstream ifs("file path");
//do whatever you want to with str;
I once did something similar to this. I had a register and login option. When registering I had them choose an username and that would be the name of the .txt file, and then the password would be stored there. (I used c_str() ). As already said, main problem is that someone could just go take a look at those files and see the password. I haven't done hashing but know how some of the simpler algorithms work from taking Security+. If you want it set up so that they can only have one account then have it save a bool i.e
bool hasRegistered = true
1 2 3 4 5 6 7 8 9 10 11
if(hasRegistered = true)
// login code here
// register code here
That would be for if the file already exists and you added an option to reset everything to create a new account. For the first time you would just check if the file is open.
1 2 3 4 5 6 7 8 9
// check whether or not there is an account
// run register code