-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImplementing Basic Password Validation in Python.py
48 lines (39 loc) · 1.64 KB
/
Implementing Basic Password Validation in Python.py
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
37
38
39
40
41
42
43
44
45
46
47
48
# Password validation in Python using the naive method
# Function to validate the password
def password_check(passwd):
SpecialSym =['$', '@', '#', '%'] # Define allowed special symbols
val = True # Initial flag to indicate the password validity
# Check password length constraints
if len(passwd) < 6:
print('Length should be at least 6')
val = False
if len(passwd) > 20:
print('Length should not be greater than 20') # Corrected the message
val = False
# Check for digits
if not any(char.isdigit() for char in passwd):
print('Password should have at least one numeral')
val = False
# Check for uppercase letters
if not any(char.isupper() for char in passwd):
print('Password should have at least one uppercase letter')
val = False
# Check for lowercase letters
if not any(char.islower() for char in passwd):
print('Password should have at least one lowercase letter')
val = False
# Check for special characters
if not any(char in SpecialSym for char in passwd):
print('Password should have at least one of the symbols $@#%')
val = False
return val # Return the validity of password
# Main function to handle the user input and validation process
def main():
passwd = input("Enter the password: ")
while not password_check(passwd): # Loop until a valid password is entered
print("Invalid password, reenter please:")
passwd = input("Enter the password: ")
print("Password is valid.")
# Driver code
if __name__ == '__main__':
main()