diff --git a/C++/PasswordStrength/Image/Moderate.PNG b/C++/PasswordStrength/Image/Moderate.PNG new file mode 100644 index 00000000..1e0326a5 Binary files /dev/null and b/C++/PasswordStrength/Image/Moderate.PNG differ diff --git a/C++/PasswordStrength/Image/Strong.PNG b/C++/PasswordStrength/Image/Strong.PNG new file mode 100644 index 00000000..31a3c2e6 Binary files /dev/null and b/C++/PasswordStrength/Image/Strong.PNG differ diff --git a/C++/PasswordStrength/Image/Weak.PNG b/C++/PasswordStrength/Image/Weak.PNG new file mode 100644 index 00000000..5f4416aa Binary files /dev/null and b/C++/PasswordStrength/Image/Weak.PNG differ diff --git a/C++/PasswordStrength/README.md b/C++/PasswordStrength/README.md new file mode 100644 index 00000000..d1d4dd85 --- /dev/null +++ b/C++/PasswordStrength/README.md @@ -0,0 +1,7 @@ +Aim: To check strength of Password in C++ + +If Password is 8-character long and have uppercase, lowercase , digit and special character then it is Strong + +If Password is 6-chacter long with uppercase or Lowercase and special character then it is Moderate + +otherwise its Weak diff --git a/C++/PasswordStrength/checkpassword.cpp b/C++/PasswordStrength/checkpassword.cpp new file mode 100644 index 00000000..4b7c6b2e --- /dev/null +++ b/C++/PasswordStrength/checkpassword.cpp @@ -0,0 +1,36 @@ +#include + +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; +}