Skip to content

Password Strength Checker in C++ #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added C++/PasswordStrength/Image/Moderate.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added C++/PasswordStrength/Image/Strong.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added C++/PasswordStrength/Image/Weak.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions C++/PasswordStrength/README.md
Original file line number Diff line number Diff line change
@@ -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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add time and space complexity

otherwise its Weak
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add sample use case or example

36 changes: 36 additions & 0 deletions C++/PasswordStrength/checkpassword.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <iostream>

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all extra spaces

using namespace std;

void CheckPassword(string& input)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add proper comments

{
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;
}