Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (54 loc) · 1.56 KB
/
Copy pathmain.py
File metadata and controls
73 lines (54 loc) · 1.56 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
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
import re
import getpass
def check_password_strength(password):
score = 0
feedback = []
# Check password length
if len(password) >= 8:
score += 1
else:
feedback.append("Password should be at least 8 characters long.")
# Check uppercase letters
if re.search(r"[A-Z]", password):
score += 1
else:
feedback.append("Add at least one uppercase letter.")
# Check lowercase letters
if re.search(r"[a-z]", password):
score += 1
else:
feedback.append("Add at least one lowercase letter.")
# Check numbers
if re.search(r"[0-9]", password):
score += 1
else:
feedback.append("Add at least one number.")
# Check special characters
if re.search(r"[^A-Za-z0-9]", password):
score += 1
else:
feedback.append("Add at least one special character.")
# Evaluate password strength
if score <= 2:
strength = "Weak"
elif score <= 4:
strength = "Medium"
else:
strength = "Strong"
return strength, feedback
def main():
print("=" * 40)
print(" PASSWORD STRENGTH CHECKER")
print("=" * 40)
password = getpass.getpass("Enter your password: ")
strength, feedback = check_password_strength(password)
print("\nPassword Strength:", strength)
if feedback:
print("\nSuggestions:")
for item in feedback:
print("-", item)
else:
print("\nYour password meets all basic requirements!")
print("\n" + "=" * 40)
if __name__ == "__main__":
main()