Skip to content

Commit b115f58

Browse files
Added fixed password validator script
1 parent a383cfd commit b115f58

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
2+
import string
3+
4+
def passwordValidator():
5+
"""
6+
Validates passwords to match specific rules
7+
:return: str
8+
"""
9+
print('\nYour password should: ')
10+
print('\t- Have a minimum length of 6;')
11+
print('\t- Have a maximum length of 12;')
12+
print('\t- Contain at least an uppercase letter;')
13+
print('\t- Contain at least a lowercase letter;')
14+
print('\t- Contain at least a number;')
15+
print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);')
16+
print('\t- Not contain space(s).')
17+
18+
userPassword = input('\nEnter a valid password: ').strip()
19+
20+
# Length check
21+
if not(6 <= len(userPassword) <= 12):
22+
return 'Invalid Password..length must be between 6 and 12'
23+
24+
# No spaces allowed
25+
if ' ' in userPassword:
26+
return 'Invalid Password..shouldn\'t contain spaces'
27+
28+
# Uppercase letter check
29+
if not any(i.isupper() for i in userPassword):
30+
return 'Invalid Password..should contain at least one uppercase letter'
31+
32+
# Lowercase letter check
33+
if not any(i.islower() for i in userPassword):
34+
return 'Invalid Password..should contain at least one lowercase letter'
35+
36+
# Number check
37+
if not any(i.isdigit() for i in userPassword):
38+
return 'Invalid Password..should contain at least one number'
39+
40+
# Special character check
41+
if not any(i in string.punctuation for i in userPassword):
42+
return 'Invalid Password..should contain at least one special character'
43+
44+
return 'Valid Password!'
45+
46+
my_password = passwordValidator()
47+
print(my_password)

0 commit comments

Comments
 (0)