I created a database like this(this is actually one part of my big program). It is working perfectly. But I need my program to find password by asking username again. It is in the switch case. How can I do it?
class LoginPage
{
private:
public:
bool Login();
void login_intro();
};
bool LoginPage::Login()
{
string username, password, name, pin;
cout << "enter username: ";
cin >> username;
cout << "enter password: ";
cin >> password;
ifstream in("newuser" + username + ".txt");
getline(in, name);
getline(in, pin);
if (name == username&&pin == password) return true;
else return false;
}
void LoginPage::login_intro()
{
start:
system("cls");
cout << "\t\t\tQUIZLET of IUT\n\n";
cout << "\t\t\t1.Register\n\t\t\t2.Login\n";
int a;
cin >> a;
if (a == 1)
{
reg:
system("cls");
string username, password, password1;
cout << "\nSelect username: "; cin >> username;
cout << "\nSelect password: "; cin >> password;
for (int i = 0; i != 50; i++)
{
cout << "\nConfirm password: "; cin >> password1;
if (password != password1) cout << "Passwords do not match!\n";
else if (password == password1) i = 49;
}
ofstream new_user("newuser" + username + ".txt", ios::app);
new_user << username << endl << password;
new_user.close();
system("cls");
goto start;
}
else if (a == 2)
{
system("cls");
CHECKPOINT:
bool status = Login();
if (!status)
{
cout << "\nIncorrect username or password\n";
cout << "1. Try again\n2. Forgot password?\n3. Don't have an account, register\n";
asd:
cin >> a;
switch (a)
{
case 1:
goto CHECKPOINT;
break;
case 2:
//I have to do something here
break;
case 3:
goto reg;
break;
default:
cout << "Please enter a proper value\n";
goto asd;
}
_getch(); system("cls");
goto CHECKPOINT;
}
else cout << "You have successfully logged in\n";
Sleep(700);
system("cls");
}
else if (a != 1 || a != 2)
{
cout << "Please enter a proper value\n";
goto start;
}
}