-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchpt7-StrongPasswordDetection.py
57 lines (43 loc) · 1.63 KB
/
chpt7-StrongPasswordDetection.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
49
50
#! python3
# Goal: Function that uses regular expressions to make sure the password string is strong
import re
# Program will run in a loop until you quit
while True:
password = input("Input a desired password: ")
if password == 'q':
exit()
elif password == 'quit':
exit()
else:
print("checking password")
# Check password requirements
# Minimum 8 characters
if len(password) >= 8:
print("Password meets the length requirements")
# Checks for lowercase
passwordRegex = re.compile(r'[a-z]')
if passwordRegex.search(password):
print("Contains atleast one lowercase letter")
else:
print("Doesn't contain atleast one lowercase letter")
# Checks for uppercase
passwordRegex = re.compile(r'[A-Z]+')
if passwordRegex.search(password):
print("Contains atleast one uppercase letter")
else:
print("Doesn't contain atleast one uppercase letter")
# Checks for numbers
passwordRegex = re.compile(r'[0-9]+')
if passwordRegex.search(password):
print("Contains atleast one number")
else:
print("Doesn't contain atleast one number")
# Checks for special characters
passwordRegex = re.compile(r'[!@#$%^&*()_+]+')
if passwordRegex.search(password):
print("Contains atleast one special character")
else:
print("Doesn't contain atleast one special character")
else:
print("Password is less than 8 characters and does not meet the recommended complexity requirements")
exit()