-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask_3
More file actions
172 lines (146 loc) · 4.18 KB
/
Task_3
File metadata and controls
172 lines (146 loc) · 4.18 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import tkinter as tk
from tkinter import messagebox
import string
def analyze_password():
"""Analyze the entered password and display its strength."""
password = password_entry.get() # Get the password from the entry field
# Check if the placeholder text is still present
if password == placeholder_text:
result_text.set("Please enter a valid password.")
return
# Initialize counters
strength = 0
lower_count = upper_count = num_count = wspace_count = special_count = 0
# Analyze the password
for char in password:
if char in string.ascii_lowercase:
lower_count += 1
elif char in string.ascii_uppercase:
upper_count += 1
elif char in string.digits:
num_count += 1
elif char == ' ':
wspace_count += 1
else:
special_count += 1
# Calculate strength
if lower_count >= 1:
strength += 1
if upper_count >= 1:
strength += 1
if num_count >= 1:
strength += 1
if wspace_count >= 1:
strength += 1
if special_count >= 1:
strength += 1
# Provide feedback based on strength
if strength == 1:
remarks = "Very bad Password 👎"
elif strength == 2:
remarks = "Not a good Password 🥲"
elif strength == 3:
remarks = "Very weak Password, consider changing ☹️"
elif strength == 4:
remarks = "It's a hard Password, but can be better 😟"
elif strength == 5:
remarks = "A very strong Password 👍"
# Display the analysis results
result_text.set(
f"Password Analysis:\n"
f"{lower_count} lowercase character(s)\n"
f"{upper_count} uppercase character(s)\n"
f"{num_count} numeric character(s)\n"
f"{wspace_count} whitespace character(s)\n"
f"{special_count} special character(s)\n"
f"\nPassword strength: {strength}\n"
f"Hint: {remarks}"
)
def clear_input():
"""Clear the password input field and results."""
password_entry.delete(0, tk.END)
result_text.set("")
set_placeholder()
def set_placeholder():
"""Set the placeholder text in the password entry field."""
password_entry.insert(0, placeholder_text)
password_entry.config(fg="grey")
def clear_placeholder(event):
"""Clear the placeholder text when the user clicks on the entry field."""
if password_entry.get() == placeholder_text:
password_entry.delete(0, tk.END)
password_entry.config(fg="black")
# Create the main Tkinter window
root = tk.Tk()
root.title("Password Strength Checker")
root.geometry("450x550")
# Set a nice background color
bg_color = "#cfe9f3" # Light blue
root.configure(bg=bg_color)
# Placeholder text
placeholder_text = "Enter password here"
# Add widgets to the GUI
title_label = tk.Label(
root,
text="Password Strength Checker",
font=("Arial", 16, "bold"),
bg=bg_color,
fg="#2c3e50",
)
title_label.pack(pady=10)
password_label = tk.Label(
root,
text="Enter your password:",
font=("Arial", 12),
bg=bg_color,
fg="#2c3e50",
)
password_label.pack(pady=5)
password_entry = tk.Entry(
root,
font=("Arial", 12),
width=30,
relief=tk.SOLID,
bg="white",
fg="grey",
)
password_entry.pack(pady=5)
set_placeholder() # Set the placeholder initially
# Bind events for placeholder functionality
password_entry.bind("<FocusIn>", clear_placeholder)
password_entry.bind("<FocusOut>", lambda event: set_placeholder() if password_entry.get() == "" else None)
analyze_button = tk.Button(
root,
text="Analyze Password",
font=("Arial", 12),
bg="#4CAF50",
fg="white",
width=20,
relief=tk.FLAT,
command=analyze_password,
)
analyze_button.pack(pady=10)
clear_button = tk.Button(
root,
text="Clear",
font=("Arial", 12),
bg="#f44336",
fg="white",
width=10,
relief=tk.FLAT,
command=clear_input,
)
clear_button.pack(pady=5)
result_text = tk.StringVar()
result_label = tk.Label(
root,
textvariable=result_text,
font=("Arial", 12),
bg=bg_color,
fg="#2c3e50",
justify="left",
wraplength=400,
)
result_label.pack(pady=10)
# Run the Tkinter event loop
root.mainloop()