-
-
Notifications
You must be signed in to change notification settings - Fork 46.7k
Added check_strong_password.py #4950
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f7a19b0
Added check_strong_password.py
Snimer 59269cb
Corrected Comment
Snimer fc642ba
Updated
Snimer 3c8418a
Updated check_strong_password.py
Snimer 95b953c
Merge branch 'TheAlgorithms:master' into strongPass
Snimer 25494c8
Ran Pre-Commit
Snimer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# This Will Check Whether A Given Password Is Strong Or Not | ||
# It Follows The Rule that Length Of Password Should Be At Least 8 Characters | ||
# And At Least 1 Lower, 1 Upper, 1 Number And 1 Special Character | ||
|
||
from string import ascii_lowercase, ascii_uppercase, digits, punctuation | ||
|
||
|
||
def strong_password_detector(password: str, min_length: int = 8) -> str: | ||
""" | ||
>>> strong_password_detector('Hwea7$2!') | ||
'This is a strong Password' | ||
|
||
>>> strong_password_detector('Sh0r1') | ||
'Your Password must be at least 8 characters long' | ||
|
||
>>> strong_password_detector('Hello123') | ||
'Password should contain UPPERCASE, lowercase, numbers, special characters' | ||
|
||
>>> strong_password_detector('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1') | ||
'This is a strong Password' | ||
|
||
>>> strong_password_detector(0) | ||
'Your Password must be at least 8 characters long' | ||
""" | ||
|
||
if len(str(password)) < 8: | ||
return "Your Password must be at least 8 characters long" | ||
|
||
upper = any(char in ascii_uppercase for char in password) | ||
lower = any(char in ascii_lowercase for char in password) | ||
num = any(char in digits for char in password) | ||
spec_char = any(char in punctuation for char in password) | ||
|
||
if upper and lower and num and spec_char: | ||
return "This is a strong Password" | ||
|
||
else: | ||
return ( | ||
"Password should contain UPPERCASE, lowercase, " | ||
"numbers, special characters" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One of the tests should be a long (like 20 char) string. Also tests for strong_password_detector(0), strong_password_detector(1.3), strong_password_detector(['H', 'w', 'e', 'a', '7', '$', '2', '!'])