-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
334 lines (263 loc) · 6.62 KB
/
Copy pathapp.py
File metadata and controls
334 lines (263 loc) · 6.62 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# ============================================
# Advanced Password Manager + Generator GUI
# Author: ChatGPT
# Python 3.10+
#
# Features:
# - Secure password generation
# - GUI management system
# - Save platform / username / password
# - Search accounts
# - Copy password
# - Password strength meter
# - SQLite database
# - Dark modern UI
#
# Install:
# pip install customtkinter pyperclip
#
# Run:
# python password_manager.py
# ============================================
import customtkinter as ctk
from tkinter import messagebox
import sqlite3
import secrets
import string
import pyperclip
import re
from datetime import datetime
# -----------------------------
# APP CONFIG
# -----------------------------
ctk.set_appearance_mode("dark")
ctk.set_default_color_theme("blue")
APP_WIDTH = 950
APP_HEIGHT = 650
# -----------------------------
# DATABASE
# -----------------------------
conn = sqlite3.connect("passwords.db")
cursor = conn.cursor()
cursor.execute("""
CREATE TABLE IF NOT EXISTS passwords (
id INTEGER PRIMARY KEY AUTOINCREMENT,
platform TEXT NOT NULL,
username TEXT NOT NULL,
password TEXT NOT NULL,
created_at TEXT
)
""")
conn.commit()
# -----------------------------
# PASSWORD GENERATOR
# -----------------------------
def generate_password(length=24):
lowercase = string.ascii_lowercase
uppercase = string.ascii_uppercase
digits = string.digits
symbols = "!@#$%^&*()_+-=[]{}?"
all_chars = lowercase + uppercase + digits + symbols
password = [
secrets.choice(lowercase),
secrets.choice(uppercase),
secrets.choice(digits),
secrets.choice(symbols)
]
password += [secrets.choice(all_chars) for _ in range(length - 4)]
secrets.SystemRandom().shuffle(password)
return ''.join(password)
# -----------------------------
# PASSWORD STRENGTH
# -----------------------------
def check_strength(password):
score = 0
if len(password) >= 12:
score += 1
if re.search(r"[A-Z]", password):
score += 1
if re.search(r"[a-z]", password):
score += 1
if re.search(r"\d", password):
score += 1
if re.search(r"[!@#$%^&*()_+\-=\[\]{}?]", password):
score += 1
if score <= 2:
return "Weak"
elif score <= 4:
return "Medium"
else:
return "Strong"
# -----------------------------
# SAVE PASSWORD
# -----------------------------
def save_password():
platform = platform_entry.get()
username = username_entry.get()
password = password_entry.get()
if not platform or not username or not password:
messagebox.showerror("Error", "All fields are required")
return
cursor.execute("""
INSERT INTO passwords(platform, username, password, created_at)
VALUES (?, ?, ?, ?)
""", (
platform,
username,
password,
datetime.now().strftime("%Y-%m-%d %H:%M:%S")
))
conn.commit()
load_passwords()
platform_entry.delete(0, "end")
username_entry.delete(0, "end")
password_entry.delete(0, "end")
messagebox.showinfo("Saved", "Password saved successfully")
# -----------------------------
# LOAD PASSWORDS
# -----------------------------
def load_passwords(search=""):
textbox.configure(state="normal")
textbox.delete("1.0", "end")
if search:
cursor.execute("""
SELECT platform, username, password, created_at
FROM passwords
WHERE platform LIKE ? OR username LIKE ?
ORDER BY id DESC
""", (f"%{search}%", f"%{search}%"))
else:
cursor.execute("""
SELECT platform, username, password, created_at
FROM passwords
ORDER BY id DESC
""")
rows = cursor.fetchall()
for row in rows:
platform, username, password, created = row
textbox.insert(
"end",
f"""
Platform : {platform}
Username : {username}
Password : {password}
Created : {created}
{'-'*50}
"""
)
textbox.configure(state="disabled")
# -----------------------------
# GENERATE BUTTON
# -----------------------------
def generate_button():
password = generate_password(24)
password_entry.delete(0, "end")
password_entry.insert(0, password)
strength = check_strength(password)
strength_label.configure(
text=f"Strength: {strength}"
)
# -----------------------------
# COPY PASSWORD
# -----------------------------
def copy_password():
password = password_entry.get()
if password:
pyperclip.copy(password)
messagebox.showinfo("Copied", "Password copied")
# -----------------------------
# SEARCH
# -----------------------------
def search_passwords():
search = search_entry.get()
load_passwords(search)
# -----------------------------
# GUI
# -----------------------------
app = ctk.CTk()
app.geometry(f"{APP_WIDTH}x{APP_HEIGHT}")
app.title("Advanced Password Manager")
# LEFT FRAME
left_frame = ctk.CTkFrame(app)
left_frame.pack(side="left", fill="y", padx=15, pady=15)
title = ctk.CTkLabel(
left_frame,
text="Password Manager",
font=("Arial", 28, "bold")
)
title.pack(pady=20)
# Platform
platform_entry = ctk.CTkEntry(
left_frame,
width=300,
placeholder_text="Platform"
)
platform_entry.pack(pady=10)
# Username
username_entry = ctk.CTkEntry(
left_frame,
width=300,
placeholder_text="Username / Email"
)
username_entry.pack(pady=10)
# Password
password_entry = ctk.CTkEntry(
left_frame,
width=300,
placeholder_text="Password"
)
password_entry.pack(pady=10)
# Strength Label
strength_label = ctk.CTkLabel(
left_frame,
text="Strength: -",
font=("Arial", 14)
)
strength_label.pack(pady=5)
# Buttons
generate_btn = ctk.CTkButton(
left_frame,
text="Generate Password",
command=generate_button,
height=40
)
generate_btn.pack(pady=10)
copy_btn = ctk.CTkButton(
left_frame,
text="Copy Password",
command=copy_password,
height=40
)
copy_btn.pack(pady=10)
save_btn = ctk.CTkButton(
left_frame,
text="Save Password",
command=save_password,
height=40
)
save_btn.pack(pady=10)
# RIGHT FRAME
right_frame = ctk.CTkFrame(app)
right_frame.pack(side="right", fill="both", expand=True, padx=15, pady=15)
search_entry = ctk.CTkEntry(
right_frame,
placeholder_text="Search platform or username"
)
search_entry.pack(fill="x", padx=10, pady=10)
search_btn = ctk.CTkButton(
right_frame,
text="Search",
command=search_passwords
)
search_btn.pack(pady=5)
textbox = ctk.CTkTextbox(
right_frame,
font=("Consolas", 14)
)
textbox.pack(fill="both", expand=True, padx=10, pady=10)
# LOAD DATA
load_passwords()
# RUN
app.mainloop()
# CLOSE DB
conn.close()