Maintenance Mode

Have Patience Working on it

Check a Password

Write a function that determines whether or not a password is good. A good password to be one that is at least 8 characters long and contains at least one upper case letter, at least one lowercase letter and at least one number.

def checkPassword(password):
# checker for upper, lower and number
has_upper = False
has_lower = False
has_num = False
# check for each character
for ch in password:
# check for upper
if ch >= "A" and ch <= "Z":
has_upper = True
# if not upper then check for lower
elif ch >= "a" and ch <= "z":
has_lower = True
# for number
elif ch >= "0" and ch <= "9": # not using else here because puntauation can also be there
has_num = True
# end if
# finally checking for length
if len(password) >= 8 and has_upper and has_lower and has_num:
return True
return False
p = input("Enter a password: ")
if checkPassword(p):
print("That's a good password.")
else:
print("That isn't a good password.")
Check a Password Check a Password Reviewed by Leaf Code on August 07, 2020 Rating: 5

No comments:

SET ADT Using Students courses example

Powered by Blogger.