-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpassword_keeper_def_func.py
384 lines (288 loc) · 12 KB
/
password_keeper_def_func.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
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
import sqlite3
from cryptography.fernet import Fernet
import password_keeper
from tkinter import * # Used for the graphical user interface (gui)
from tkinter import messagebox
# Query the DB and returning ALL records
def show_all(key, username):
# Get key
f = Fernet(key)
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("SELECT rowid, * FROM " + username)
items = c.fetchall()
# Create window to show results
root = Tk()
root.title("Your Passwords:")
root.iconbitmap("ExtraSupportContent/florestechnologylogo.ico")
width = 600
height = 800
root.geometry(str(width) + "x" + str(height))
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_coordinate = int((screen_width / 2) - (width / 2))
y_coordinate = int((screen_height / 2) - (height / 2))
root.geometry(str(width) + "x" + str(height) + "+" + str(x_coordinate) + "+" + str(y_coordinate))
"""# This is not a viable option because the label makes so many wierd stuff and I dont have the time or energy to make this work
# Create A Main Frame
main_frame = Frame(root)
main_frame.pack(fill=BOTH, expand=1)
# Create A Canvas
my_canvas = Canvas(main_frame)
my_canvas.pack(side=LEFT, fill=BOTH, expand=1)
# Add A Scrollbar To The Canvas
my_scrollbar = ttk.Scrollbar(main_frame, orient=VERTICAL, command=my_canvas.yview)
my_scrollbar.pack(side=RIGHT, fill=Y)
# Configure The Canvas
my_canvas.configure(yscrollcommand=my_scrollbar.set)
my_canvas.bind('<Configure>', lambda e: my_canvas.configure(scrollregion=my_canvas.bbox("all")))
# Create ANOTHER Frame INSIDE the Canvas
second_frame = Frame(my_canvas)
# Add that New frame To a Window In The Canvas
my_canvas.create_window((0, 0), window=second_frame, anchor="nw")"""
sb = Scrollbar(root)
sb.pack(side=RIGHT, fill=Y)
mylist = Listbox(root, yscrollcommand=sb.set, width=width, height=(height-20))
# Show results
for item in items:
# Decrypt and decode info
decrypted_user = f.decrypt(item[1])
original_user = decrypted_user.decode()
decrypted_pass = f.decrypt(item[2])
original_pass = decrypted_pass.decode()
decrypted_email = f.decrypt(item[3])
original_email = decrypted_email.decode()
decrypted_info = f.decrypt(item[4])
original_info = decrypted_info.decode()
# Format results
"""info = "Id: " + str(item[0]) + "\n" + "User/Website: " + original_user + "\n" + "Password: " + original_pass \
+ "\n" + "Email: " + original_email + "\n\n" + "Info: " + original_info"""
mylist.insert(END, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
mylist.insert(END, "Id: " + str(item[0]))
mylist.insert(END, "User/Website: " + original_user)
mylist.insert(END, "Password: " + original_pass)
mylist.insert(END, "Email: " + original_email)
mylist.insert(END, "Info: " + original_info)
mylist.insert(END, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
mylist.insert(END, "")
""" # The list is a better workaround for this
Label(second_frame, text=info).grid(row=len(items), column=0, pady=10, padx=10)"""
def go_back():
root.destroy()
password_keeper.mainPasswordKeeper(username)
Button(root, text="Return", command=go_back).pack()
mylist.pack(side=LEFT)
sb.config(command=mylist.yview)
# Commit changes
conn.commit()
# Close connection
conn.close()
# Add ONE new record to the table
def add_one(username, user, password, email, info):
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("INSERT INTO " + username + " VALUES (?, ?, ?, ?)", (user, password, email, info))
# Commit changes
conn.commit()
# Close connection
conn.close()
# Delete record from table
def delete_one(username, id_var):
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("DELETE from " + username + " WHERE rowid = " + id_var)
# Commit changes
conn.commit()
# Close connection
conn.close()
# Lookup with WHERE
def name_lookup(key, username, name):
# Get key
f = Fernet(key)
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("SELECT rowid, * FROM " + username)
items = c.fetchall()
toplvl = Toplevel()
toplvl.title("Search...")
toplvl.iconbitmap("ExtraSupportContent/florestechnologylogo.ico")
width = 600
height = 800
screen_width = toplvl.winfo_screenwidth()
screen_height = toplvl.winfo_screenheight()
x_coordinate = int((screen_width / 2) - (width / 2))
y_coordinate = int((screen_height / 2) - (height / 2))
toplvl.geometry(str(width) + "x" + str(height))
toplvl.geometry(str(width) + "x" + str(height) + "+" + str(x_coordinate) + "+" + str(y_coordinate))
sb = Scrollbar(toplvl)
sb.pack(side=RIGHT, fill=Y)
mylist = Listbox(toplvl, yscrollcommand=sb.set, width=width, height=(height - 20))
# Searches through all items
for item in items:
# Decrypts the name of the record
decrypted_name = f.decrypt(item[1]) # The rowid is in the '0' position, so name is in '1'
original_name = decrypted_name.decode()
# Compares the record to what the user entered
if original_name == name:
decrypted_pass = f.decrypt(item[2])
original_pass = decrypted_pass.decode()
decrypted_email = f.decrypt(item[3])
original_email = decrypted_email.decode()
decrypted_info = f.decrypt(item[4])
original_info = decrypted_info.decode()
# Format results
mylist.insert(END, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
mylist.insert(END, "Id: " + str(item[0]))
mylist.insert(END, "User/Website: " + original_name)
mylist.insert(END, "Password: " + original_pass)
mylist.insert(END, "Email: " + original_email)
mylist.insert(END, "Info: " + original_info)
mylist.insert(END, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
mylist.insert(END, "")
def go_back():
toplvl.destroy()
Button(toplvl, text="Return", command=go_back).pack()
mylist.pack(side=LEFT)
sb.config(command=mylist.yview)
toplvl.mainloop()
# Commit changes
conn.commit()
# Close connection
conn.close()
def id_lookup(key, username, id):
# Get key
f = Fernet(key)
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("SELECT rowid, * FROM " + username + " WHERE rowid = (?)", id)
items = c.fetchall()
toplvl = Toplevel()
toplvl.title("Search...")
toplvl.iconbitmap("ExtraSupportContent/florestechnologylogo.ico")
width = 600
height = 800
screen_width = toplvl.winfo_screenwidth()
screen_height = toplvl.winfo_screenheight()
x_coordinate = int((screen_width / 2) - (width / 2))
y_coordinate = int((screen_height / 2) - (height / 2))
toplvl.geometry(str(width) + "x" + str(height))
toplvl.geometry(str(width) + "x" + str(height) + "+" + str(x_coordinate) + "+" + str(y_coordinate))
try:
# Searches through all items
for item in items:
decrypted_name = f.decrypt(item[1])
original_name = decrypted_name.decode()
# Compares the record to what the user entered
if int(id) == item[0]: # The rowid is in the '0' position
decrypted_pass = f.decrypt(item[2])
original_pass = decrypted_pass.decode()
decrypted_email = f.decrypt(item[3])
original_email = decrypted_email.decode()
decrypted_info = f.decrypt(item[4])
original_info = decrypted_info.decode()
# Format results
info = "Id: " + str(item[0]) + "\n" + "User/Website: " + original_name + "\n" + "Password: " + original_pass \
+ "\n" + "Email: " + original_email + "\n\n" + "Info: " + original_info
Label(toplvl, text=info, font=("Times New Roman", 15)).pack()
except:
messagebox.showerror("Error", "There is no registry with that ID.")
def go_back():
toplvl.destroy()
Button(toplvl, text="Return", font=("Times New Roman", 15), command=go_back).pack()
toplvl.mainloop()
# Commit changes
conn.commit()
# Close connection
conn.close()
def email_lookup(key, username, email):
# Get key
f = Fernet(key)
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
# Query database
c.execute("SELECT rowid, * FROM " + username)
items = c.fetchall()
toplvl = Toplevel()
toplvl.title("Search...")
toplvl.iconbitmap("ExtraSupportContent/florestechnologylogo.ico")
width = 600
height = 800
screen_width = toplvl.winfo_screenwidth()
screen_height = toplvl.winfo_screenheight()
x_coordinate = int((screen_width / 2) - (width / 2))
y_coordinate = int((screen_height / 2) - (height / 2))
toplvl.geometry(str(width) + "x" + str(height))
toplvl.geometry(str(width) + "x" + str(height) + "+" + str(x_coordinate) + "+" + str(y_coordinate))
sb = Scrollbar(toplvl)
sb.pack(side=RIGHT, fill=Y)
mylist = Listbox(toplvl, yscrollcommand=sb.set, width=width, height=(height - 20))
# Searches through all items
for item in items:
# Decrypts the name of the record
decrypted_name = f.decrypt(item[1]) # The rowid is in the '0' position, so name is in '1'
original_name = decrypted_name.decode()
decrypted_email = f.decrypt(item[3]) # The email is in position '3'
original_email = decrypted_email.decode()
# Compares the record to what the user entered
if original_email == email:
decrypted_pass = f.decrypt(item[2])
original_pass = decrypted_pass.decode()
decrypted_info = f.decrypt(item[4])
original_info = decrypted_info.decode()
# Format results
mylist.insert(END, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
mylist.insert(END, "Id: " + str(item[0]))
mylist.insert(END, "User/Website: " + original_name)
mylist.insert(END, "Password: " + original_pass)
mylist.insert(END, "Email: " + original_email)
mylist.insert(END, "Info: " + original_info)
mylist.insert(END, "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
mylist.insert(END, "")
def go_back():
toplvl.destroy()
Button(toplvl, text="Return", command=go_back).pack()
mylist.pack(side=LEFT)
sb.config(command=mylist.yview)
toplvl.mainloop()
# Commit changes
conn.commit()
# Close connection
conn.close()
# Update record
def update_one(username, user, password, email, info, id):
# Connect to database
conn = sqlite3.connect("registryUsers.db")
# Create a cursor
c = conn.cursor()
c.execute(" UPDATE " + username + " SET username = (?) WHERE rowid = (?)", (user, id))
c.execute(" UPDATE " + username + " SET password = (?) WHERE rowid = (?)", (password, id))
c.execute(" UPDATE " + username + " SET email = (?) WHERE rowid = (?)", (email, id))
c.execute(" UPDATE " + username + " SET info = (?) WHERE rowid = (?)", (info, id))
# Commit changes to db
conn.commit()
# Close connection to db
conn.close()
# Creates table for specific user
def createTable(username):
connection = sqlite3.connect("registryUsers.db")
cursor = connection.cursor()
cursor.execute("CREATE TABLE " + username + "(username text, password text, email text, info text)")
connection.commit()
connection.close()