Skip to content

Commit

Permalink
Merge pull request #47 from UBC-MDS/strength_function
Browse files Browse the repository at this point in the history
fixed special character regex
  • Loading branch information
Kierst01 authored Jan 19, 2024
2 parents f395808 + 5e9717d commit 968ece4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/passwordler/password_strength.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ 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'")
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))
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',
'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:
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'
Expand Down

0 comments on commit 968ece4

Please sign in to comment.