-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcheckpassword.cpp
36 lines (34 loc) · 1.1 KB
/
checkpassword.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
#include <iostream>
using namespace std;
void CheckPassword(string& input)
{
int n = input.length(); //check length of string
bool hasLower = false, hasUpper = false;
bool hasDigit = false, specialChar = false;
for (int i = 0; i < n; i++) // from character 1 to end of string
{
if (islower(input[i])) //check if char is lowercase
hasLower = true;
else if (isupper(input[i])) //check if char is uppercase
hasUpper = true;
else if (isdigit(input[i])) //check if char is digit
hasDigit = true;
else //check if char is special character
specialChar = true;
}
cout << " Strength of password: ";
if (hasLower && hasUpper && hasDigit && specialChar && (n >= 8))
cout << "Strong" << endl;
else if ((hasLower || hasUpper) && specialChar && (n >= 6))
cout << "Moderate" << endl;
else
cout << "Weak" << endl;
}
int main()
{
string str;
cout<<"\n Enter Password : ";
getline(cin,str); //get a string input
CheckPassword(str);
return 0;
}