1
+
2
+ import string
3
+
4
+ def passwordValidator ():
5
+ """
6
+ Validates passwords to match specific rules
7
+ :return: str
8
+ """
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;' )
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 ('\n Enter 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