-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
78 lines (69 loc) · 2.61 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import string
def check_password_strength(password: str) -> int:
"""Returns a score indicating the strength of the password.
A higher score means the password is stronger.
"""
global x
score = 0
x = 0
# Check if the password contains at least one character from each required character class
if any(c.isupper() for c in password):
score += 1
x = 1
if any(c.islower() for c in password):
score += 1
x += 1
if any(c.isdigit() for c in password):
score += 1
x += 1
if any(c in string.punctuation for c in password):
score += 1
x += 1
if x < 4:
return score
# Check if the password is long enough
if len(password) >= 8:
score += 1
if len(password) >= 12:
score += 1
if len(password) >= 16:
score += 1
if len(password) >= 20:
score += 1
return score
def check_password(password: str) -> None:
"""Checks the password for various issues and prints a message indicating its strength."""
# Read the list of common passwords from the file
with open("common.txt", "r") as f:
common_passwords = set(f.read().splitlines())
# Check if the password is too common
if password in common_passwords:
print("Password is too common. Your password strength is 0.")
return
# Check the password strength
score = check_password_strength(password)
if score == 0:
print ("Password is too weak")
if x < 4:
print ("Password must contain at least an uppercase letter, lowercase letter, special character and at least one digit")
elif score == 1:
print("Password is weak.")
if x < 4:
print ("Password must contain at least an uppercase letter, lowercase letter, special character and at least one digit")
elif score == 2:
print("Password is average.")
if x < 4:
print ("Password must contain at least an uppercase letter, lowercase letter, special character and at least one digit")
elif score == 3:
print("Password is not that strong.")
if x < 4:
print ("Password must contain at least an uppercase letter, lowercase letter, special character and at least one digit")
elif score == 4:
print("Password is not that strong.")
if x < 4:
print ("Password must contain at least an uppercase letter, lowercase letter, special character and at least one digit")
else:
print("Password is extremely strong.")
while True:
password = input("Enter password: ")
check_password(password)