Define a function named "isValidPassword" which take a string as parameter. The function will then check if the supplied string fulfilled the following password criterias: 1) must have combination of uppercase and lowercase 2) must have at least 3 digits 3) must have at least 2 special character (including whitespace). 4) must have at least 10 characters (combination of alphanumeric and special symbol) The function will return a Boolean value i.e. True if all criterias are met or return False otherwise. Make sure you test your function with every single possible input that may return False value as well.
def isValidPassword(password):
sym = 0
num = 0
upper = False
lower = False
if len(password) >= 10:
for s in password:
if s.isalpha():
if s.islower():
lower = True
else:
upper = True
elif s.isdigit():
num += 1
else:
sym += 1
if upper and lower and num >= 3 and sym >= 2:
return True
else:
return False
print(isValidPassword("Hello123&%")) #True
Comments
Leave a comment