0
Login function
Hello everyone can someone tell me how to insert a simple login function into my program in C++, I want it to be the first thing to show when the program compiles and then continue with the other parts.
2 odpowiedzi
+ 1
#include <iostream>
using namespace std;
int main () {
string userName;
string userPassword;
int loginAttempt = 0;
while (loginAttempt < 5) { cout << "Please enter your user name: ";
cin >> userName; cout << "Please enter your user password: ";
cin >> userPassword;
if (userName == "greg" && userPassword == "dunn")
{ cout << "Welcome Greg!\n"; break;
}
else if (userName == "patrick" && userPassword == "dunn")
{
cout << "Welcome Patrick!\n"; break;
} else
{
cout << "Invalid login attempt. Please try again.\n" << '\n'; loginAttempt++; } }
if (loginAttempt == 5)
{
cout << "Too many login attempts! The program will now terminate."; return 0; }
cout << "Thank you for logging in.\n";
Return 0;
}
0
Poema Berisha Yes I can help you with that, Today I did the sololearn PasswordValidator challenge with C++ which can be used in your login system.
This is the challenge problem
https://www.sololearn.com/learn/7028/?ref=app
Here is my solution
https://code.sololearn.com/c2ux5eUkeY7g/?ref=app
If you want login system file based I can help you with that.