-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
181 lines (147 loc) · 7.97 KB
/
app.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
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
173
174
175
176
177
178
179
180
181
# ---------------------------------------------------------------------------- #
# PassGen #
# ---------------------------------------------------------------------------- #
from modules import * # Import all custom modules in /modules dir
import tkinter as tk
import customtkinter as ctk
from PIL import Image
import pyperclip
# ----------------------------------- Setup ---------------------------------- #
# App
app = ctk.CTk()
app.title("PassGen")
app.geometry("800x500")
app.resizable(False, False)
# --------------------------------- Variable --------------------------------- #
# Variables
password = "Password"
theme = ChangeTheme(app)
# Tk variables
password_tkvar = tk.StringVar(value=password)
password_length_tkvar = tk.IntVar(value=15)
password_uppercase_tkvar = tk.BooleanVar(value=True)
password_lowercase_tkvar = tk.BooleanVar(value=True)
password_numbers_tkvar = tk.BooleanVar(value=True)
password_symbols_tkvar = tk.BooleanVar(value=True)
btn_img_generate = ctk.CTkImage(
light_image=Image.open("assets/buttons/generate-black.png"),
dark_image=Image.open("assets/buttons/generate-white.png"),
size=(30,30)
)
btn_img_copy = ctk.CTkImage(
light_image=Image.open("assets/buttons/copy-black.png"),
dark_image=Image.open("assets/buttons/copy-white.png"),
size=(30,30)
)
# --------------------------------- Functions -------------------------------- #
# Function that generates password and update app
def generate_password():
global password
# Generate password using generator module
password = PasswordGenerator(
length=password_length_tkvar.get(),
uppercase=password_uppercase_tkvar.get(),
lowercase=password_lowercase_tkvar.get(),
numbers=password_numbers_tkvar.get(),
symbols=password_symbols_tkvar.get()
).generate_password()
# Get password grade using evaluate module
password_grade = PasswordEvaluator(password).evaluate_strength()
# Determine progress bar color
if password_grade <= 20:
progressbar_color = "#e74c3c"
if password_grade >= 20:
progressbar_color = "#f36512"
if password_grade >= 40:
progressbar_color = "#ffbd2e"
if password_grade >= 60:
progressbar_color = "#92c934"
if password_grade >= 80:
progressbar_color = "#59c934"
# Update widgets
password_tkvar.set(password)
progressbar_password.set(password_grade/100)
progressbar_password.configure(progress_color=progressbar_color)
print()
print("PASSWORD:", password)
print("GRADE:", password_grade)
return password
# Function that maskes sure at least one checkbox is clicked
def update_checkboxes_state(checkbox):
# Get the current state of the clicked checkbox
current_state = checkbox.get()
# Check the state of each checkbox
states = [
checkbox_customize_1.get(),
checkbox_customize_2.get(),
checkbox_customize_3.get(),
checkbox_customize_4.get()
]
# If only one checkbox is True, disable it
if states.count(True) == 1:
for cb in [checkbox_customize_1, checkbox_customize_2, checkbox_customize_3, checkbox_customize_4]:
if cb.get():
cb.configure(state=tk.DISABLED)
else:
# Enable all checkboxes
checkbox_customize_1.configure(state=tk.NORMAL)
checkbox_customize_2.configure(state=tk.NORMAL)
checkbox_customize_3.configure(state=tk.NORMAL)
checkbox_customize_4.configure(state=tk.NORMAL)
# ---------------------------------- Widgets --------------------------------- #
# Frame password
frame_password = ctk.CTkFrame(app, corner_radius=10)
label_password = ctk.CTkLabel(frame_password, textvariable=password_tkvar, font=("Arial", 25))
progressbar_password = ctk.CTkProgressBar(frame_password, height=10, width=785, progress_color="#59c934", fg_color="")
button_password_1 = ctk.CTkButton(frame_password, image=btn_img_generate, height=30, width=20, hover_color=("#c9c9c9","#242424"), corner_radius=20 , fg_color="transparent", text="", command=generate_password)
button_password_2 = ctk.CTkButton(frame_password, image=btn_img_copy, height=30, width=20, hover_color=("#c9c9c9","#242424"), corner_radius=20, fg_color="transparent", text="", command=(lambda: pyperclip.copy(password)))
# Frame customize
frame_customize = ctk.CTkFrame(app, corner_radius=10)
label_customize_1 = ctk.CTkLabel(frame_customize, text="Customize Password", font=("Arial Bold", 20))
label_customize_2 = ctk.CTkLabel(frame_customize, text="Password Length", font=("Arial", 18))
label_customize_3 = ctk.CTkLabel(master=frame_customize, textvariable=password_length_tkvar, corner_radius=5, fg_color=("#c9c9c9","#242424"), font=("Arial", 18))
slider_customize = ctk.CTkSlider(master=frame_customize, from_ = 1, to = 40, width=300, variable=password_length_tkvar, progress_color="#59c934", button_color="#429526", button_hover_color="#2b6218", fg_color=("#c9c9c9","#242424"))
button_debug = ctk.CTkButton(master=frame_customize, text="DEBUG", command=generate_password, fg_color="#429526")
# Frame customize checbox
frame_checkbox = ctk.CTkFrame(frame_customize, fg_color="transparent", corner_radius=10)
checkbox_customize_1 = ctk.CTkCheckBox(master=frame_checkbox, variable=password_uppercase_tkvar, text="Uppercase", border_width=2, fg_color="#429526", hover_color="#2b6218", font=("Arial", 18), command=(lambda: update_checkboxes_state(checkbox_customize_1)))
checkbox_customize_2 = ctk.CTkCheckBox(master=frame_checkbox, variable=password_lowercase_tkvar, text="Lowercase", border_width=2, fg_color="#429526", hover_color="#2b6218", font=("Arial", 18), command=(lambda: update_checkboxes_state(checkbox_customize_2)))
checkbox_customize_3 = ctk.CTkCheckBox(master=frame_checkbox, variable=password_numbers_tkvar, text="Numbers", border_width=2, fg_color="#429526", hover_color="#2b6218", font=("Arial", 18), command=(lambda: update_checkboxes_state(checkbox_customize_3)))
checkbox_customize_4 = ctk.CTkCheckBox(master=frame_checkbox, variable=password_symbols_tkvar, text="Symbols", border_width=2, fg_color="#429526", hover_color="#2b6218", font=("Arial", 18), command=(lambda: update_checkboxes_state(checkbox_customize_4)))
# ---------------------------------- Layout ---------------------------------- #
# Configure app grid
app.columnconfigure(0, weight=1, uniform="a")
app.rowconfigure((0,1,2,3,4), weight=1, uniform="a")
# Frame password
frame_password.grid(column=0, row=0, sticky="nsew", padx=10, pady=10)
label_password.place(relx=0.02, rely=0.45, anchor="w")
progressbar_password.place(relx=0.5, rely=0.98, anchor="center")
button_password_1.pack(side="right", padx=5)
button_password_2.pack(side="right")
# Frame customize
frame_customize.grid(column=0, row=1, rowspan=5, sticky="nsew", padx=10, pady=10)
label_customize_1.place(relx=0.02, rely=0.08, anchor="w")
label_customize_2.place(relx=0.02, rely=0.40, anchor="w")
label_customize_3.place(relx=0.02, rely=0.5, anchor="w")
slider_customize.place(relx=0.06, rely=0.5, anchor="w")
#button_debug.place(relx=0.02, rely=0.9, anchor="w")
# Frame customize checbox
frame_customize.columnconfigure((0,1,3), weight=1, uniform="a")
frame_customize.rowconfigure(0, weight=1, uniform="a")
frame_checkbox.grid(column=3, row=0, sticky="nsew", padx=10, pady=10)
checkbox_customize_1.place(relx=0.4, rely=0.05, anchor="nw")
checkbox_customize_2.place(relx=0.4, rely=0.15, anchor="nw")
checkbox_customize_3.place(relx=0.4, rely=0.25, anchor="nw")
checkbox_customize_4.place(relx=0.4, rely=0.35, anchor="nw")
# ---------------------------------- Events ---------------------------------- #
app.bind('<Control-t>', (lambda event: theme.toggle_theme()))
app.bind('<Control-c>', (lambda event: pyperclip.copy(password)))
app.bind('<Control-g>', (lambda event: generate_password()))
# ------------------------------------ Run ----------------------------------- #
# Set default theme
theme.set_dark_theme()
#ChangeTheme(app).set_light_theme()
# Generate first password
generate_password()
# Run the app
app.mainloop()