-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcpa_lab_4_5_7_(7)-B.cpp
63 lines (50 loc) · 1.2 KB
/
cpa_lab_4_5_7_(7)-B.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
using namespace std;
int main()
{
string temp;
cin >> temp;
std::string password = temp;
bool flag = true;
temp = " ";
if (password.size() < 8)
{
cout << "The password must be 8 characters long" << endl;
flag = false;
}
temp = "";
for (int i = 0; i < password.size(); i++)
temp += tolower(password[i]);
if (temp == password)
{
cout << "The password must have at least one upper-case letter" << endl;
flag = false;
}
temp = "";
for (int i = 0; i < password.size(); i++)
temp += toupper(password[i]);
if (temp == password)
{
cout << "The password must have at least one lower-case letter" << endl;
flag = false;
}
temp = "";
for (int i = 0; i < password.size(); i++)
if (!isdigit(password[i])) temp += password[i];
if (temp == password)
{
cout << "The password must have at least one digit" << endl;
flag = false;
}
temp = "";
for (int i = 0; i < password.size(); i++)
if (isdigit(password[i]) || isalpha(password[i])) temp += password[i];
if (temp == password)
{
cout << "The password must have at least one special character." << endl;
flag = false;
}
if (flag)
cout << "The password is valid" << endl;
return 0;
}