I am trying to generate a password checker in python that uses the following rules to determine the strength of a user's password.
The user's password is WEAK if it is less than 6 characters long. The user's password is STRONG if it contains at least 13 characters, at least 1 lower case letter at least 1 capital letter and at least 1 numerical digit. The user has a MEDIUM password if it is neither a strong or weak password.
I have generated the following code:
def strengthOfPassword ( pass ):
strongness = 0
up = 0
low = 0
num = 0
for i in pass:
if i.islower():
low += 1
if i.isupper():
up += 1
if i.isdigit():
num +=1
print (len(pass))
if len(pass) >= 13:
if up > 0 and low > 0 and num > 0:
strongness = "STRONG PASSWORD"
if len(pass) < 6:
strongness = "WEAK PASSWORD"
else:
strongness = "MEDIUM PASSWORD"
return strongness
strengthOfPassword("2Benji3all4Kiwi")
The code works for most test cases, however for the string "2Benji3all4Kiwi", the code incorrectly states that this is a medium password, rather than a strong password, despite meeting all of the criteria for a strong password. Why is this?
Aucun commentaire:
Enregistrer un commentaire