0
how to make a login program
User input username and password, if it false it will loop and ask user to enter again.
1 Odpowiedź
+ 1
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
string user_name;
string password;
bool is_login = false;
int no_of_attempts = 0;
int max_no_of_attempts = 5;
do
{
cout << "Enter Username: ";
cin >> user_name;
cout << endl << "Enter password: ";
cin >> password;
if(user_name == "User" && password == "password")
{
is_login = true;
break;
}
else
{
no_of_attempts +=1;
}
}
while(is_login == false && no_of_attempts < max_no_of_attempts);
if(is_login == true)
{
cout << "Welcome, "<<user_name << endl;
}
else
{
cout << "Login failed" << endl;
}
return 0;
}