-
Notifications
You must be signed in to change notification settings - Fork 59
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
otherwise its Weak | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add sample use case or example |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove all extra spaces |
||
using namespace std; | ||
|
||
void CheckPassword(string& input) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
} |
There was a problem hiding this comment.
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