-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdead.cpp
More file actions
76 lines (63 loc) · 1.8 KB
/
dead.cpp
File metadata and controls
76 lines (63 loc) · 1.8 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <iostream>
using namespace std;
int main() {
string username, password, confirm;
string savedUser, savedPass;
int choice;
int attempts = 3;
cout << "=== Menu ===\n";
cout << "1. Sign up\n";
cout << "2. Log in\n";
cout << "3. Exit\n";
cout << "Enter choice: ";
cin >> choice;
cin.ignore();
if(choice == 1) {
cout << "\n=== Sign up ===\n";
cout << "Create username: ";
getline(cin, savedUser);
while(true) {
cout << "Create password: ";
getline(cin, password);
cout << "Confirm password: ";
getline(cin, confirm);
if(password == confirm) {
savedPass = password;
cout << "Password confirmed\n";
cout << "Account created successfully\n";
break;
} else {
cout << "Password do not match\n";
}
}
}
cout << "\nMenu\n";
cout << "1 Sign in\n";
cout << "2 Log in\n";
cout << "3 Exit\n";
cout << "Enter choice: ";
cin >> choice;
cin.ignore();
if(choice == 2) {
string user, pass;
cout << "\nLog in\n";
while(attempts > 0) {
cout << "Enter username: ";
getline(cin, user);
cout << "Enter password: ";
getline(cin, pass);
if(user == savedUser && pass == savedPass) {
cout << "Login successfully\n";
break;
} else {
attempts--;
cout << "Wrong username or password\n";
cout << "Attempts left: " << attempts << endl;
}
if(attempts == 0) {
cout << "Too many failed attempts. Access denied.\n";
}
}
}
return 0;
}