-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (59 loc) · 2.21 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
import re
def check_password_strength(password):
# Criteria for password strength
length_criteria = len(password) >= 8
uppercase_criteria = any(char.isupper() for char in password)
lowercase_criteria = any(char.islower() for char in password)
digit_criteria = any(char.isdigit() for char in password)
special_char_criteria = bool(re.search(r"[!@#$%^&*(),.?\":{}|<>]", password))
# Count satisfied criteria
criteria_met = sum(
[
length_criteria,
uppercase_criteria,
lowercase_criteria,
digit_criteria,
special_char_criteria,
]
)
# Determine strength level
if criteria_met == 5:
strength = "Very Strong"
elif criteria_met == 4:
strength = "Strong"
elif criteria_met == 3:
strength = "Moderate"
elif criteria_met == 2:
strength = "Weak"
else:
strength = "Very Weak"
# Feedback
feedback = []
if not length_criteria:
feedback.append("Password should be at least 8 characters long.")
if not uppercase_criteria:
feedback.append("Include at least one uppercase letter.")
if not lowercase_criteria:
feedback.append("Include at least one lowercase letter.")
if not digit_criteria:
feedback.append("Include at least one digit.")
if not special_char_criteria:
feedback.append("Include at least one special character (e.g., !@#$%^&*).")
return strength, feedback
def main():
print("Welcome to the Password Complexity Checker!")
while True:
password = input("Enter a password to check its strength: ")
strength, feedback = check_password_strength(password)
print(f"\nPassword Strength: {strength}")
if feedback:
print("Suggestions to improve your password:")
for suggestion in feedback:
print(f"- {suggestion}")
# Ask user if they want to check another password or exit
choice = input("\nDo you want to check another password? (yes/no): ").strip().lower()
if choice != "yes":
print("Thank you for using the Password Complexity Checker! Goodbye!")
break
if __name__ == "__main__":
main()