From 0015d5defee0257a9d42ce0081e1700179a58d2a Mon Sep 17 00:00:00 2001 From: Kiersten Gilberg Date: Thu, 18 Jan 2024 17:30:02 -0800 Subject: [PATCH 1/3] fixed special character regex --- src/passwordler/password_strength.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/passwordler/password_strength.py b/src/passwordler/password_strength.py index a8dea63..4a2c2ce 100644 --- a/src/passwordler/password_strength.py +++ b/src/passwordler/password_strength.py @@ -17,7 +17,7 @@ def password_strength(password): """ count_uppercase = len(re.findall("[A-Z]", password)) count_numbers = len(re.findall('[0-9]', password)) - count_special_chars = len(re.findall('[!-\/:-@[-`{-~]', password)) + count_special_chars = len(re.findall('[!-/:-@\\[-`{-~]', password)) length = len(password) common_passwords = ['123456', 'password', '12345', '12345678', 'qwerty', '1234567890', '1234', 'baseball', 'dragon', 'football', '1234567', 'monkey', 'letmein', 'abc123', From ba000175e896b9758fbc6ecb2cbb8f99df23ce18 Mon Sep 17 00:00:00 2001 From: Kiersten Gilberg Date: Thu, 18 Jan 2024 17:56:00 -0800 Subject: [PATCH 2/3] moved TypeError to the top of the function --- src/passwordler/password_strength.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/passwordler/password_strength.py b/src/passwordler/password_strength.py index 4a2c2ce..d54cba1 100644 --- a/src/passwordler/password_strength.py +++ b/src/passwordler/password_strength.py @@ -15,6 +15,9 @@ def password_strength(password): Returns: str: a rating of either 'weak', 'good' or 'strong' """ + if not isinstance(password, str): + raise TypeError("'password' should be of type 'string'") + count_uppercase = len(re.findall("[A-Z]", password)) count_numbers = len(re.findall('[0-9]', password)) count_special_chars = len(re.findall('[!-/:-@\\[-`{-~]', password)) @@ -24,8 +27,6 @@ def password_strength(password): '111111', 'mustang', 'access', 'shadow', 'master', 'michael', 'superman', '696969', '123123', 'batman', 'trustno1'] - if not isinstance(password, str): - raise TypeError("'password' should be of type 'string'") if password == '': raise ValueError("'password' cannot be an empty string") elif length >= 12 and count_uppercase >= 1 and count_numbers >= 1 and count_special_chars >= 1 and password not in common_passwords: From 5e9717d437c622735042139689f78e69939e8876 Mon Sep 17 00:00:00 2001 From: Kiersten Gilberg Date: Thu, 18 Jan 2024 18:00:36 -0800 Subject: [PATCH 3/3] moved ValueError --- src/passwordler/password_strength.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/passwordler/password_strength.py b/src/passwordler/password_strength.py index d54cba1..7ab3ade 100644 --- a/src/passwordler/password_strength.py +++ b/src/passwordler/password_strength.py @@ -17,6 +17,8 @@ def password_strength(password): """ if not isinstance(password, str): raise TypeError("'password' should be of type 'string'") + elif password == '': + raise ValueError("'password' cannot be an empty string") count_uppercase = len(re.findall("[A-Z]", password)) count_numbers = len(re.findall('[0-9]', password)) @@ -27,9 +29,7 @@ def password_strength(password): '111111', 'mustang', 'access', 'shadow', 'master', 'michael', 'superman', '696969', '123123', 'batman', 'trustno1'] - if password == '': - raise ValueError("'password' cannot be an empty string") - elif length >= 12 and count_uppercase >= 1 and count_numbers >= 1 and count_special_chars >= 1 and password not in common_passwords: + if length >= 12 and count_uppercase >= 1 and count_numbers >= 1 and count_special_chars >= 1 and password not in common_passwords: return 'Your password is: Strong' elif length >= 8 and (count_uppercase + count_numbers + count_special_chars) >= 2 and password not in common_passwords: return 'Your password is: Good'