-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSecure Password-Based Authentication System.cpp
More file actions
99 lines (78 loc) · 3.11 KB
/
Secure Password-Based Authentication System.cpp
File metadata and controls
99 lines (78 loc) · 3.11 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* NAME - MAYANK YADAV
PRN - 24070123060
CLASS - ENTC A-3 */
#include <iostream>
#include <string>
using namespace std;
int main() {
string user_defined_password;
string input_password;
bool has_special = false;
cout << "\n=============================================\n";
cout << "| # Secure Access Initialization # |\n";
cout << "=============================================\n";
cout << "| Create a secure password. |\n";
cout << "| Requirements: |\n";
cout << "| - At least 4 characters |\n";
cout << "| - Must contain a special character |\n";
cout << "| Allowed: @, #, $, %, &, ! |\n";
cout << "---------------------------------------------\n";
cout << "Create your password: ";
cin >> user_defined_password;
// Check length
if (user_defined_password.length() < 4) {
cout << "\nPassword too short. Must be at least 4 characters.\n";
return 0;
}
for (int i = 0; i < user_defined_password.length(); i++) {
char ch = user_defined_password[i];
if (ch == '@' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '!') {
has_special = true;
break;
}
}
if (!has_special) {
cout << "\nPassword must include at least one special character (@, #, $, %, &, !).\n";
return 0;
}
cout << "\n\n=============================================\n";
cout << "| >> Authentication Required << |\n";
cout << "=============================================\n";
cout << "Enter your password to unlock the system: ";
cin >> input_password;
while (true) {
if (input_password != user_defined_password) {
cout << "\n Access Denied: Incorrect Password.\n";
cout << "Try again: ";
cin >> input_password;
} else {
cout << "\n Access Granted. System Unlocked \n";
break;
}
}
cout << "\n=============================================\n";
cout << "| Session Terminated. Stay Secure. |\n";
cout << "=============================================\n";
}
/* OUTPUT
=============================================
| # Secure Access Initialization # |
=============================================
| Create a secure password. |
| Requirements: |
| - At least 4 characters |
| - Must contain a special character |
| Allowed: @, #, $, %, &, ! |
---------------------------------------------
Create your password: 627@
=============================================
| >> Authentication Required << |
=============================================
Enter your password to unlock the system: 627
Access Denied: Incorrect Password.
Try again: 627@
Access Granted. System Unlocked
=============================================
| Session Terminated. Stay Secure. |
=============================================
=== Code Execution Successful === */