-
-
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
Changes from 3 commits
f7a19b0
59269cb
fc642ba
3c8418a
95b953c
25494c8
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,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 | ||
|
||
|
||
import re | ||
|
||
|
||
def strong_password_detector(password: str) -> 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') | ||
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. 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', '!']) |
||
'Password should contain UPPERCASE, lowercase, numbers, special characters' | ||
""" | ||
|
||
upper = re.compile(r"[A-Z]") | ||
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. Would |
||
lower = re.compile(r"[a-z]") | ||
num = re.compile(r"[0-9]") | ||
spec_char = re.compile(r"[!@#$\^&\*\(\):;\'\"<>,\.\?\/|]") | ||
|
||
if re.compile(r"\s").search(password) or len(password) < 8: | ||
return "Your Password must be at least 8 characters long" | ||
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. Move these lines before line 22 so that we do not do the work on lines 22-24 if the password is too short. |
||
|
||
elif ( | ||
upper.search(password) | ||
and lower.search(password) | ||
and num.search(password) | ||
and spec_char.search(password) | ||
): | ||
return "This is a strong Password" | ||
|
||
else: | ||
return ( | ||
"Password should contain UPPERCASE, lowercase, " | ||
"numbers, special characters" | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
import doctest | ||
|
||
doctest.testmod() |
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.
and make appropriate changes in the function.