-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
283 lines (223 loc) · 11.9 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
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
from tkinter import *
from tkinter import messagebox
import sqlite3
import random
import pyperclip
import userverify
from popup import Popup
from userverify import UserVerify
import os
import sys
import pandas as pd
import time
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
# --------------------CONSTANTS--------------------#
pass_logo = resource_path("password.png")
db = resource_path("password.db")
FONT = ('Arial', 25, 'italic')
FONT2 = ('Consolas', 12, 'bold')
FONT3 = ('Consolas', 12, 'bold')
FONT4 = ('Arial', 10, 'normal')
DEEP_BLUE = "#1b4b98"
LIGHT_BLUE = "#00bde4"
GRAY = "#c8d2db"
LETTERS = ['A', 'a', 'B', 'b', 'C', 'c', 'D', 'd', 'E', 'e', 'F', 'f', 'G', 'g', 'H', 'h', 'I', 'i', 'J', 'j',
'K', 'k', 'L', 'l', 'M', 'm', 'N', 'n', 'O', 'o', 'P', 'p', 'Q', 'q', 'R', 'r', 'S', 's', 'T', 't',
'U', 'u', 'V', 'v', 'W', 'w', 'X', 'x', 'Y', 'y', 'Z', 'z']
SYMBOLS = ['!' '@', '#', '$', '%', '^', '*', '&', '(', ')', '+', '=', '_', '/']
NUMS = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
# --------------------QUERIES--------------------#
SEARCH_QUERY = '''select username, password, createdate from password where website =? and userid =?'''
INSERT_QUERY = '''insert into password values(?,?,?,?,?,?)'''
DELETE_QUERY = '''delete from password where website =? and userid =?'''
UPDATE_QUERY = '''update password set password =?, updatedate=? where website=? and userid=?'''
# --------------------DATABASE CONNECTION--------------------#
conn = sqlite3.connect(db)
cursor = conn.cursor()
# --------------------SECURITY VERIFICATION--------------------#
user = UserVerify()
user.verify_credentials_window()
active_user = userverify.USER
if userverify.STATUS:
# --------------------WINDOW SETUP--------------------#
window = Tk()
window.title("Password Manager")
window.config(bg="white")
window.minsize(height=630, width=500)
canvas = Canvas(width=300, height=300, highlightthickness=0, bg="white")
logo = PhotoImage(file=pass_logo)
canvas.create_image(230, 150, image=logo)
canvas.place(x=30, y=10)
window.resizable(False, False)
# --------------------LABELS--------------------#
title = Label(text="Pass Manager", font=FONT, bg="white", fg=DEEP_BLUE)
title.place(x=150, y=250)
username_label = Label(text="USERNAME", font=FONT2, bg="white", fg=DEEP_BLUE, padx=10, pady=10)
username_label.place(x=50, y=320)
password_label = Label(text="PASSWORD", font=FONT2, bg="white", fg=DEEP_BLUE, padx=10, pady=10)
password_label.place(x=50, y=360)
website_label = Label(text="WEBSITE", font=FONT2, bg="white", fg=DEEP_BLUE, padx=10, pady=10)
website_label.place(x=50, y=400)
# --------------------TEXT BOXES--------------------#
username_entry = Text(font=FONT4)
username_entry.focus()
username_entry.config(border=0, highlightcolor=LIGHT_BLUE, highlightthickness=2, width=39, height=0, bg=GRAY)
username_entry.place(x=150, y=330)
password_entry = Text(font=FONT4)
password_entry.config(border=0, highlightcolor=LIGHT_BLUE, highlightthickness=2, width=25, height=0, bg=GRAY)
password_entry.place(x=150, y=370)
website_entry = Text(font=FONT4)
website_entry.config(border=0, highlightcolor=LIGHT_BLUE, highlightthickness=2, width=25, height=0, bg=GRAY)
website_entry.place(x=150, y=410)
# --------------------BUTTON COMMANDS--------------------#
# --------------------SHOW TIMESTAMP--------------------#
def show_timestamp():
try:
cursor.execute("select updatedate, website from password where userid=?", (active_user,))
dates = cursor.fetchall()
last_update = max(dates)
messagebox.showinfo("Last Updated Entry", f"Website: {last_update[1]}\nTimestamp: {last_update[0]}")
except:
messagebox.showerror("Error", "Some error has occurred!")
# --------------------SEARCHING FOR ENTRIES--------------------#
def entry_search():
website_search = website_entry.get("1.0", "end-1c")
username_entry.delete("1.0", "end")
password_entry.delete("1.0", "end")
user_info = cursor.execute(SEARCH_QUERY, (website_search.lower(), active_user,))
if not website_search:
messagebox.showerror("Error", "Fill out all required fields!")
elif len(user_info.fetchall()) == 0:
messagebox.showerror("Message", "No such entry exists!")
else:
user_info = cursor.execute(SEARCH_QUERY, (website_search.lower(), active_user,))
user_tuple = user_info.fetchall()
username = user_tuple[0][0]
pwd = user_tuple[0][1]
username_entry.insert(INSERT, username)
password_entry.insert(INSERT, pwd)
# --------------------INSERTING NEW PASSWORDS--------------------#
def insert_passwd():
website_search = website_entry.get("1.0", "end-1c")
password_search = password_entry.get("1.0", "end-1c")
username_search = username_entry.get("1.0", "end-1c")
if not website_search or not password_search or not username_search:
messagebox.showerror("Error", "Fill out all required fields!")
else:
try:
cursor.execute(INSERT_QUERY,
(username_search.lower(), password_search.lower(), website_search.lower(), active_user,
time.time(), time.time()))
except:
messagebox.showerror("Error", "Some error has occurred or Website already exists!")
else:
popup = Popup()
message_label1 = Label(popup, text=f"Username: {username_search}", font=FONT4)
message_label1.place(x=30, y=10)
message_label2 = Label(popup, text=f"Password: {password_search}", font=FONT4)
message_label2.place(x=30, y=30)
message_label3 = Label(popup, text=f"Website: {website_search}", font=FONT4)
message_label3.place(x=30, y=50)
confirm = Button(popup, text="CONFIRM?", font=FONT3, width=8, relief="solid", borderwidth=0,
bg=DEEP_BLUE,
fg=LIGHT_BLUE, command=lambda: confirm_query(popup))
confirm.place(x=110, y=90)
# --------------------DELETE PASSWORDS--------------------#
def delete_password():
website_search = website_entry.get("1.0", "end-1c")
if not website_search:
messagebox.showerror("Error", "Fill out all required fields!")
else:
try:
cursor.execute(DELETE_QUERY, (website_search, active_user))
except:
messagebox.showerror("Error", "Some error has occurred")
else:
popup = Popup()
message_label = Label(popup, text=f"This will delete {website_search}'s password", font=FONT4)
message_label.place(x=35, y=40)
confirm = Button(popup, text="CONFIRM?", font=FONT3, width=8, relief="solid", borderwidth=0,
bg=DEEP_BLUE,
fg=LIGHT_BLUE, command=lambda: confirm_query(popup))
confirm.place(x=110, y=90)
# --------------------UPDATE PASSWORDS--------------------#
def update_password():
website_search = website_entry.get("1.0", "end-1c")
password_search = password_entry.get("1.0", "end-1c")
cursor.execute(SEARCH_QUERY, (website_search.lower(), active_user))
if not website_search or not password_search:
messagebox.showerror("Error", "Fill out all required fields!")
elif len(cursor.fetchall()) == 0:
messagebox.showerror("Error", "Website entry does not exist!")
else:
try:
cursor.execute(UPDATE_QUERY, (password_search, time.time(), website_search, active_user))
except:
messagebox.showerror("Error", "Some error has occurred!")
else:
popup = Popup()
message_label = Label(popup, text=f"This will update {website_search}'s password", font=FONT4)
message_label.place(x=35, y=40)
confirm = Button(popup, text="CONFIRM?", font=FONT3, width=8, relief="solid", borderwidth=0,
bg=DEEP_BLUE,
fg=LIGHT_BLUE, command=lambda: confirm_query(popup))
confirm.place(x=110, y=90)
# --------------------GENERATE PASSWORD--------------------#
def generate_pass():
password_entry.delete("1.0", "end")
new_pass = random.sample(LETTERS, 4)
new_pass.extend(random.sample(SYMBOLS, 4))
new_pass.extend(random.sample(NUMS, 4))
random.shuffle(new_pass)
generated_pass = "".join(new_pass)
password_entry.insert(INSERT, generated_pass)
pyperclip.copy(generated_pass)
def confirm_query(popup):
conn.commit()
popup.after(1, lambda: popup.destroy())
password_entry.delete("1.0", "end")
username_entry.delete("1.0", "end")
website_entry.delete("1.0", "end")
# --------------------GENERATE REPORT--------------------#
def view_saved_pass():
try:
info = cursor.execute("select username, website, password from password where userid=?", (active_user,))
if(len(info.fetchall()) == 0):
messagebox.showerror("Error!", "No saved passwords for current users!")
else:
cursor.execute("select username, website, password from password where userid=?", (active_user, ))
db_df = pd.DataFrame(cursor.fetchall())
db_df.to_csv(f'{active_user}.csv', index=False)
messagebox.showinfo("Exported!", "Data successfully exported to csv!")
except:
messagebox.showerror("Error","Some error has occurred")
# --------------------BUTTONS--------------------#
search_button = Button(text="SEARCH", font=FONT3, width=8, relief="solid", borderwidth=0, bg=DEEP_BLUE,
fg=LIGHT_BLUE,
command=entry_search, padx=5)
search_button.place(x=338, y=407)
generate_button = Button(text="GENERATE", font=FONT3, width=8, relief="solid", borderwidth=0, bg=DEEP_BLUE,
fg=LIGHT_BLUE, padx=5, command=generate_pass)
generate_button.place(x=338, y=367)
save_button = Button(text="SAVE", font=FONT3, width=12, relief="solid", borderwidth=0, bg=LIGHT_BLUE, fg=DEEP_BLUE,
command=insert_passwd)
save_button.place(x=310, y=470)
update_button = Button(text="UPDATE", font=FONT3, width=12, relief="solid", borderwidth=0, bg=LIGHT_BLUE,
fg=DEEP_BLUE,
command=update_password)
update_button.place(x=62, y=470)
delete_button = Button(text="DELETE", font=FONT3, width=12, relief="solid", borderwidth=0, bg=LIGHT_BLUE,
fg=DEEP_BLUE,
command=delete_password)
delete_button.place(x=186, y=470)
view_pass = Button(text="VIEW ALL SAVED PASSWORDS", font=FONT3, width=39, relief="solid", borderwidth=0,
bg=DEEP_BLUE, fg=LIGHT_BLUE, padx=2.5, command=view_saved_pass)
view_pass.place(x=62, y=510)
view_update = Button(text="VIEW LAST UPDATE", font=FONT3, width=39, relief="solid", borderwidth=0,
bg=LIGHT_BLUE, fg=DEEP_BLUE, padx=2.5, command=show_timestamp)
view_update.place(x=62, y=550)
# conn.close()
window.mainloop()