password and username check in Game

Hi Guys, I'm currently trying to make a game with register system and log-in system. I've already got the register done but I'm still stuck on reading username and password. How can I read the the password that matches the username when they registered, not mistaking other usernames' password?

#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
#include <Windows.h>
using namespace std;
int main()
{
string password,username;
int choice;
choice = 0;
while (choice == 0)
{
ifstream FileIn;
FileIn.open("Welcome.txt", ios::in); // this is just an animation for welcome and choice for press 1 to register and press 2 to log-in
while(!FileIn.eof())
{
char c;
FileIn.get(c);
Sleep(30);
cout<<c; }
FileIn.close();
system("pause");
cin>>choice;
if(choice==1)
{ cout<<"Please enter your username"<<endl;
cin>>username;
username = username+ ' ';
cout<<"Please enter your password ( Numbers only )"<<endl;
cin>>password;
password = password + "\n";
cout<<"Press 0 go to the Menu any other key to end "<<endl;
cin>>choice;
}
}
ofstream myfile ("profile.txt", fstream::app);
{
if(myfile.is_open())
myfile << username;
myfile << password;
myfile.close();
}
if (choice==2)// choice 2 is to log-in, idk how to read username and password, pls help!

return 0;
}
Are you saying that you want to validate the username and password matches that when they registered? If so, sounds like you need to calculate a hash value of the username and password. So, you need to format a string that contains both the username and password, and then calculate a hash value. Then, when they login to the game you create a string containing the username and password and from that calculate a hash value, compare this hash value to the hash value generated on registration, if they match then they have the right credentials. Don't store the username and password as that is in-secure.
Last edited on
Topic archived. No new replies allowed.