-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathPassword_Validator.py
More file actions
35 lines (32 loc) · 1.17 KB
/
Password_Validator.py
File metadata and controls
35 lines (32 loc) · 1.17 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
import re
#re is a built in module in python that provides support of regular expressions
#regular expressions are used to chcek the rpesence of a certain pattern in a string.
# function to check whether the password is valid or not.
def validator(password):
flag = 0
while True:
if len(password)<8 or len(password)>16: #length limiter
flag = -1
break
elif not re.search("[a-z]",password): #presence of lowercase letter
flag = -1
break
elif not re.search("[A-Z]",password): #presence of uppercase letter
flag = -1
break
elif not re.search("[0-9]",password): #presence of digit
flag = -1
break
elif not re.search("[@#$&_]",password): #presence of special character
flag = -1
break
elif re.search("\s", password): #check if space present.
flag = -1
break
else:
print("This is a valid password")
break
if flag ==-1:
print("This is not a valid password")
password = input("Enter the password:")
validator(password)