-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisc.cpp
More file actions
47 lines (34 loc) · 1.19 KB
/
Copy pathdisc.cpp
File metadata and controls
47 lines (34 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <string>
using namespace std;
int main() {
int max_array = 5;
string usernames[max_array] = {"admin", "user1", "guest", "negachan", "tabaranza"};
string passwords[max_array] = {"admin123", "pass123", "guest123", "nega", "tabaranza123"};
string inputUser, inputPass;
int attempts = 0; // we start from 0 so when running while loop it will add 1 attempt every time it failed to login
bool loginSuccess = false;
while(attempts < 3 && !loginSuccess) { // 3 max attempts
cout << "\nLogin System\n";
cout << "Enter Username: ";
cin >> inputUser;
cout << "Enter Password: ";
cin >> inputPass;
for(int i = 0; i < max_array; i++) {
if(inputUser == usernames[i] && inputPass == passwords[i]) {
loginSuccess = true;
break;
}
}
if(loginSuccess) {
cout << "Login Successful! Welcome " << inputUser << endl;
} else {
cout << "Invalid username or password.\n";
attempts++;
}
}
if(!loginSuccess) {
cout << "\nAccount Locked after 3 failed attempts.\n";
}
return 0;
}