From f7a19b035a94e86a81ce01c17fc6fe9d0072c262 Mon Sep 17 00:00:00 2001 From: Snimer Date: Sun, 3 Oct 2021 13:55:38 +0530 Subject: [PATCH 1/5] Added check_strong_password.py --- other/check_strong_password.py | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 other/check_strong_password.py diff --git a/other/check_strong_password.py b/other/check_strong_password.py new file mode 100644 index 000000000000..a51d9e2bbb37 --- /dev/null +++ b/other/check_strong_password.py @@ -0,0 +1,44 @@ +# This Will Check Whether A Giving 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 atleast 8 characters long' + + >>> strong_password_detector('Hello123') + 'Your Password should contain both UPPERCASE and lowercase letters with atleast 1 digit and 1 special character' + """ + + upper = re.compile(r"[A-Z]") + 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 atleast 8 characters long" + + 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 "Your Password should contain both UPPERCASE and lowercase letters with atleast 1 digit and 1 special character" + + +if __name__ == "__main__": + import doctest + + doctest.testmod() From 59269cba19f6bc9e5fa52a431e0693eb3b881f00 Mon Sep 17 00:00:00 2001 From: Snimer Date: Sun, 3 Oct 2021 13:58:29 +0530 Subject: [PATCH 2/5] Corrected Comment --- other/check_strong_password.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/other/check_strong_password.py b/other/check_strong_password.py index a51d9e2bbb37..e3244e9ae545 100644 --- a/other/check_strong_password.py +++ b/other/check_strong_password.py @@ -1,4 +1,4 @@ -# This Will Check Whether A Giving Password Is Strong Or Not +# 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 fc642baea6cf871f2375b8e0d9d1d2751d723691 Mon Sep 17 00:00:00 2001 From: Snimer Date: Sun, 3 Oct 2021 14:52:54 +0530 Subject: [PATCH 3/5] Updated --- other/check_strong_password.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/other/check_strong_password.py b/other/check_strong_password.py index e3244e9ae545..64d05e3d0f11 100644 --- a/other/check_strong_password.py +++ b/other/check_strong_password.py @@ -12,10 +12,10 @@ def strong_password_detector(password: str) -> str: 'This is a strong Password' >>> strong_password_detector('Sh0r1') - 'Your Password must be atleast 8 characters long' + 'Your Password must be at least 8 characters long' >>> strong_password_detector('Hello123') - 'Your Password should contain both UPPERCASE and lowercase letters with atleast 1 digit and 1 special character' + 'Password should contain UPPERCASE, lowercase, numbers, special characters' """ upper = re.compile(r"[A-Z]") @@ -24,7 +24,7 @@ def strong_password_detector(password: str) -> str: spec_char = re.compile(r"[!@#$\^&\*\(\):;\'\"<>,\.\?\/|]") if re.compile(r"\s").search(password) or len(password) < 8: - return "Your Password must be atleast 8 characters long" + return "Your Password must be at least 8 characters long" elif ( upper.search(password) @@ -35,7 +35,10 @@ def strong_password_detector(password: str) -> str: return "This is a strong Password" else: - return "Your Password should contain both UPPERCASE and lowercase letters with atleast 1 digit and 1 special character" + return ( + "Password should contain UPPERCASE, lowercase, " + "numbers, special characters" + ) if __name__ == "__main__": From 3c8418a661c9f5561f171a343ee168a053ff824c Mon Sep 17 00:00:00 2001 From: Snimer Date: Wed, 20 Oct 2021 08:37:47 +0530 Subject: [PATCH 4/5] Updated check_strong_password.py --- other/check_strong_password.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/other/check_strong_password.py b/other/check_strong_password.py index 64d05e3d0f11..51b9a9b9b700 100644 --- a/other/check_strong_password.py +++ b/other/check_strong_password.py @@ -2,8 +2,7 @@ # 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 +from string import ascii_uppercase, ascii_lowercase, digits, punctuation def strong_password_detector(password: str) -> str: @@ -16,22 +15,23 @@ def strong_password_detector(password: str) -> str: >>> strong_password_detector('Hello123') 'Password should contain UPPERCASE, lowercase, numbers, special characters' - """ - upper = re.compile(r"[A-Z]") - lower = re.compile(r"[a-z]") - num = re.compile(r"[0-9]") - spec_char = re.compile(r"[!@#$\^&\*\(\):;\'\"<>,\.\?\/|]") + >>> strong_password_detector('Hello1238udfhiaf038fajdvjjf!jaiuFhkqi1') + 'This is a strong Password' - if re.compile(r"\s").search(password) or len(password) < 8: + >>> 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" - elif ( - upper.search(password) - and lower.search(password) - and num.search(password) - and spec_char.search(password) - ): + 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: From 25494c8e870c9b2d670ed601dcbf8e06721e524d Mon Sep 17 00:00:00 2001 From: Snimerjot Singh Date: Wed, 20 Oct 2021 08:57:11 +0530 Subject: [PATCH 5/5] Ran Pre-Commit --- other/check_strong_password.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/other/check_strong_password.py b/other/check_strong_password.py index 51b9a9b9b700..95bb327addf4 100644 --- a/other/check_strong_password.py +++ b/other/check_strong_password.py @@ -2,10 +2,10 @@ # 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_uppercase, ascii_lowercase, digits, punctuation +from string import ascii_lowercase, ascii_uppercase, digits, punctuation -def strong_password_detector(password: str) -> str: +def strong_password_detector(password: str, min_length: int = 8) -> str: """ >>> strong_password_detector('Hwea7$2!') 'This is a strong Password'