-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathpassword_validator_fixed.py
More file actions
47 lines (36 loc) · 1.54 KB
/
password_validator_fixed.py
File metadata and controls
47 lines (36 loc) · 1.54 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
35
36
37
38
39
40
41
42
43
44
45
46
47
import string
def passwordValidator():
"""
Validates passwords to match specific rules
:return: str
"""
print('\nYour password should: ')
print('\t- Have a minimum length of 6;')
print('\t- Have a maximum length of 12;')
print('\t- Contain at least an uppercase letter;')
print('\t- Contain at least a lowercase letter;')
print('\t- Contain at least a number;')
print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);')
print('\t- Not contain space(s).')
userPassword = input('\nEnter a valid password: ').strip()
# Length check
if not(6 <= len(userPassword) <= 12):
return 'Invalid Password..length must be between 6 and 12'
# No spaces allowed
if ' ' in userPassword:
return 'Invalid Password..shouldn\'t contain spaces'
# Uppercase letter check
if not any(i.isupper() for i in userPassword):
return 'Invalid Password..should contain at least one uppercase letter'
# Lowercase letter check
if not any(i.islower() for i in userPassword):
return 'Invalid Password..should contain at least one lowercase letter'
# Number check
if not any(i.isdigit() for i in userPassword):
return 'Invalid Password..should contain at least one number'
# Special character check
if not any(i in string.punctuation for i in userPassword):
return 'Invalid Password..should contain at least one special character'
return 'Valid Password!'
my_password = passwordValidator()
print(my_password)