-
Notifications
You must be signed in to change notification settings - Fork 0
/
Password Complexity.py
69 lines (56 loc) · 1.96 KB
/
Password Complexity.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
import tkinter as tk
from tkinter import messagebox
def check_password_complexity(password):
"""
Checks the complexity of a password
"""
# Initialize a flag to indicate if the password is valid
is_valid = True
strength = "Weak"
# Check if the password is at least 12 characters long
if len(password) < 12:
is_valid = False
else:
strength = "Strong"
# Check if the password contains at least one uppercase letter
if not re.search("[A-Z]", password):
is_valid = False
else:
if strength == "Strong":
strength = "Excellent"
# Check if the password contains at least one lowercase letter
if not re.search("[a-z]", password):
is_valid = False
else:
if strength == "Strong":
strength = "Excellent"
# Check if the password contains at least one digit
if not re.search("[0-9]", password):
is_valid = False
else:
if strength == "Strong":
strength = "Excellent"
# Check if the password contains at least one special character
if not re.search("[!@#$%^&*()_+=-{};:'<>,./?]", password):
is_valid = False
else:
if strength == "Strong":
strength = "Excellent"
return is_valid, strength
def check_password():
password = password_entry.get()
is_valid, strength = check_password_complexity(password)
if is_valid:
messagebox.showinfo("Password Strength", f"Password is {strength}")
else:
messagebox.showerror("Password Strength", "Password is weak. Please try again.")
root = tk.Tk()
root.title("Password Strength Checker")
password_label = tk.Label(root, text="Enter a password:")
password_label.pack()
password_entry = tk.Entry(root, show="*")
password_entry.pack()
check_button = tk.Button(root, text="Check Password", command=check_password)
check_button.pack()
root.mainloop()