-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathPassword.py
More file actions
36 lines (29 loc) · 1.11 KB
/
Password.py
File metadata and controls
36 lines (29 loc) · 1.11 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
"""Write a Python program to check the validity of a password (input from users)
Rules :
At least 1 letter between [a-z] and 1 letter between [A-Z]
At least 1 number between [0-9].
At least 1 character from [$#@].
Minimum length 6 characters.
Maximum length 16 characters.
If password is not valid throw ValueError with a proper error message
for each rule. If the password is valid print a success message.
Use some from raise, except, assert, else and finally keywords."""
import re
p= input("Input your password :")
x = True
while x:
if (len(p)<6 or len(p)>16):
raise ValueError ("Length has to be between 6-16 characters.")
elif not re.search("[a-z]",p):
raise ValueError('You have to "$","#","@"')
elif not re.search("[0-9]",p):
raise ValueError("You should use at least one digit number.")
elif not re.search("[A-Z]",p):
raise ValueError("A capital letter must be used.")
elif not re.search("[$#@]",p):
raise ValueError("A symbol must be used.")
else:
print("Valid Password")
x=False
break
print("\n Your password is : ",p)