-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_check.cpp
43 lines (38 loc) · 931 Bytes
/
password_check.cpp
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
#include <iostream>
#include <string>
int main() {
std::string password;
std::cin >> password;
bool is_valid = true;
int is_upper = 0, is_lower = 0,
is_digit = 0, is_other = 0;
// length check
if (password.length() < 8 || password.length() > 14) {
is_valid = false;
}
// ASCII check + character diversity
for (char c : password) {
if (c >= 33 && c <= 126) {
if (isupper(c)) {
is_upper = 1;
} else if (islower(c)) {
is_lower = 1;
} else if (isdigit(c)) {
is_digit = 1;
} else is_other = 1;
} else {
is_valid = false;
}
}
if (is_upper + is_lower +
is_digit + is_other < 3) {
is_valid = false;
}
// final checks
if (is_valid) {
std::cout << "YES";
} else {
std::cout << "NO";
}
return 0;
}