Skip to content

Commit 09f0ba3

Browse files
committed
added script
1 parent e34ea58 commit 09f0ba3

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

Password Validator/main.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import string
2+
3+
def passwordValidator():
4+
"""
5+
Validates passwords to match specific rules
6+
: return: str
7+
"""
8+
# display rules that a password must conform to
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 or a lowercase letter')
13+
print('\t- Contain at least a number;')
14+
print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);')
15+
print('\t- Not contain space(s).')
16+
# get user's password
17+
userPassword = input('\nEnter a valid password: ').strip()
18+
# check if user's password conforms
19+
# to the rules above
20+
if not(6 <= len(userPassword) <= 12):
21+
message = 'Invalid Password..your password should have a minimum '
22+
message += 'length of 6 and a maximum length of 12'
23+
return message
24+
if ' ' in userPassword:
25+
message = 'Invalid Password..your password shouldn\'t contain space(s)'
26+
return message
27+
if not any(i in string.ascii_letters for i in userPassword):
28+
message = 'Invalid Password..your password should contain at least '
29+
message += 'an uppercase letter and a lowercase letter'
30+
return message
31+
if not any(i in string.digits for i in userPassword):
32+
message = 'Invalid Password..your password should contain at least a number'
33+
return message
34+
if not any(i in string.punctuation for i in userPassword):
35+
message = 'Invalid Password..your password should contain at least a special character'
36+
return message
37+
else:
38+
return 'Valid Password!'
39+
40+
my_password = passwordValidator()
41+
print(my_password)

0 commit comments

Comments
 (0)