simple password program c 2b 2b source code

Solutions on MaxInterview for simple password program c 2b 2b source code by the best coders in the world

showing results for - "simple password program c 2b 2b source code"
Tomas
11 Jul 2020
1#include <iostream>
2using namespace std;
3
4int main ()
5{
6    string userName;
7    string userPassword;
8    int loginAttempt = 0;
9
10    while (loginAttempt < 5)
11    {
12        cout << "Please enter your user name: ";
13        cin >> userName;
14        cout << "Please enter your user password: ";
15        cin >> userPassword;
16
17        if (userName == "greg" && userPassword == "dunn")
18        {
19            cout << "Welcome Greg!\n";
20            break;
21        }
22        else if (userName == "patrick" && userPassword == "dunn")
23        {
24            cout << "Welcome Patrick!\n";
25            break;
26        }
27        else
28        {
29            cout << "Invalid login attempt. Please try again.\n" << '\n';
30            loginAttempt++;
31        }
32    }
33    if (loginAttempt == 5)
34    {
35            cout << "Too many login attempts! The program will now terminate.";
36            return 0;
37    }
38
39    cout << "Thank you for logging in.\n";
40}