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 ('\n Your 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 ('\n Enter 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