Skip to content

Commit 5811693

Browse files
authored
Create password_checker
1 parent 4589db8 commit 5811693

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

password_checker

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

0 commit comments

Comments
 (0)