-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathe27b1_password_checker.py
More file actions
executable file
·34 lines (28 loc) · 1.27 KB
/
e27b1_password_checker.py
File metadata and controls
executable file
·34 lines (28 loc) · 1.27 KB
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
#!/usr/bin/env python3
"""Solution to chapter 6, exercise 27, beyond 1: password_checker"""
import string
def create_password_checker(min_uppercase, min_lowercase, min_punctuation, min_digits):
def check_password(password):
if len([one_character
for one_character in password
if one_character in string.ascii_uppercase]) < min_uppercase:
print(f'Not enough uppercase letters; min is {min_uppercase}')
return False
elif len([one_character
for one_character in password
if one_character in string.ascii_lowercase]) < min_lowercase:
print(f'Not enough lowercase letters; min is {min_lowercase}')
return False
elif len([one_character
for one_character in password
if one_character in string.punctuation]) < min_punctuation:
print(f'Not enough punctuation; min is {min_punctuation}')
return False
elif len([one_character
for one_character in password
if one_character in string.digits]) < min_digits:
print(f'Not enough digits; min is {min_digits}')
return False
else:
return True
return check_password