how to make a login program | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to make a login program

User input username and password, if it false it will loop and ask user to enter again.

23rd Aug 2016, 1:16 PM
Nhfa
Nhfa - avatar
1 Answer
+ 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; }
23rd Aug 2016, 4:37 PM
Anvar
Anvar - avatar