-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpassword_checker.py
34 lines (28 loc) · 1.1 KB
/
password_checker.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# In this exercise you will write a function that determines whether or not a password is good. We will define
# a good password to be a one that is at least 8 characters long and contains at least one uppercase letter,
# at least one lowercase letter, and at least one number. Your function should return true if the password
# passed to it as its only parameter is good. Otherwise it should return false. Include a main program that
# reads a password from the user and reports whether or not it is good.
-
def checkPassword(password):
has_upper = False
has_lower = False
has_num = False
for ch in password:
if ch >= 'A' and ch <= 'Z':
has_upper = True
elif ch >= 'a' and ch <= 'z':
has_lower = True
elif ch >= '0' and ch <= '9':
has_num = True
if len(password) >= 8 and has_upper and has_lower and has_num:
return True
return False
def main():
p = input("Enter ya password: " )
if checkPassword(p):
print("Password is good")
else:
print("Password is bad")
if __name__ == "__main__":
main()