forked from AllenCompSci/Hacktoberfest
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPasswordStrength.cpp
More file actions
72 lines (60 loc) · 2.1 KB
/
Copy pathPasswordStrength.cpp
File metadata and controls
72 lines (60 loc) · 2.1 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
#include <iostream>
using namespace std;
class PasswordStrength
{
private:
string password;
public:
friend istream& operator>>(istream& fin, PasswordStrength& pass)
{
fin >> pass.password;
return fin;
}
void strength()
{
bool hasLetter = false;
bool hasDigit = false;
bool hasUpperCase = false;
bool hasLowerCase = false;
bool hasMuchLetter = false;
if(this->password.length()>=8)
hasMuchLetter = true;
for(int i=0; i<this->password.length(); i++)
{
if (isupper(this->password[i]))
{
hasUpperCase = true;
}
if (islower(this->password[i]))
{
hasLowerCase = true;
}
if (isalpha(this->password[i]))
{
hasLetter = true;
}
if(isdigit(this->password[i]))
{
hasDigit = true;
}
}
if(hasLetter && hasDigit && hasUpperCase && hasLowerCase && hasMuchLetter)
cout<<"very strong";
else if(hasLetter && hasDigit && (hasUpperCase || hasLowerCase) && hasMuchLetter)
cout<<"strong";
else if(hasLetter && hasDigit && hasUpperCase==false && hasLowerCase==false && hasMuchLetter)
cout<<"good";
else if(hasLetter && hasDigit && password.length()==false && hasUpperCase==false && hasLowerCase==false)
cout<<"weak";
else if((hasLetter==false && hasDigit) || (hasLetter && hasDigit==false) && password.length()==false && hasUpperCase==false && hasLowerCase==false)
cout<<"very weak";
else
cout<<"weak";
}
};
int main()
{
PasswordStrength pass;
cin>>pass;
pass.strength();
}