Hey there,
I'm writing a chatting system, like an instant messenger, that runs over my school's shared HD (accessed by all computers on the network). I use Ubuntu at home, and the school runs XP, so I do all my compiling and testing at school, and all the writing at home. The concept I need help with makes up a large portion of the program, and if I'm doing it wrong, I'll basically have to rewrite it... so help here would save a lot of potential trouble.
"users.data" is the file where all the username and password information is stored (writing an encrypter for it later). Every even numbered line is a username, and every odd numbered line is a password. The entered username is passed to this function, it searches the file for that username, then saves the following line, which should be the password to the specified username, as the password. It then calls the function which handles prompting the user for the correct password. Will this code work as I need it to? Specifically the 'for' loop.
Thanks in advance.Code:void getPass(string userName) { string tempName, password; ifstream userNameDB("users.data"); for (int i = 0; i != userNameDB.eof(); i = i + 2) { userNameDB >> tempName; if (tempName == userName) { i++; userNameDB >> password; userNameDB.close(); logInPASS(userName, password); } } userNameDB.close(); cout << endl << "Error fetching password for " << userName << "." << endl; writeError(1); return -1; }