forked from Sameer164/Password_saver_App
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassSaver.py
573 lines (471 loc) · 25.4 KB
/
PassSaver.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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
import sqlite3
import random
import string
import sys
from tkinter import *
from tkinter import font as tkfont
import random
questions = ["What high school did you attend?", "What’s your favorite movie?",
"What is the name of your favorite pet?", "What is your favorite food?",
"What was your favorite childhood toy?", "What was the make of your first car?",
"In what city were you born?"]
CLEAR_ALL = ['label1', 'label2', 'enter', 'code_entry', 'welcome_text', 'broad_security', 'spec_security',
'ans_entry', 'enter_secq', 'shiftcreateacc', 'save',
'createacc_invalid_message', 'invalid_code_message', 'code_text', 'code_warning', 'name_entry',
'enter_name', 'invalid_name', 'next1', 'next2', 'sqmenu', 'sqanswer', 'set_answer', 'back', 'select',
'done', 'CreateAccEndMessage1', 'CreateAccEndMessage2', 'LoggedInMessage', 'ViewPasswordMessage', 'search',
'savewebsite', 'WebsiteNameMessage', 'AlreadySavedMessage', 'savepassword1', 'EnterPasswordMessage1',
'PasswordSavedMessage', 'retrn', 'new', 'view', "savePasswordAnywayBt", "saveAnywayBt", 'savepassword2',
'savePasswordBt', 'EnterPasswordMessage2', 'savedmessage', 'SearchInsteadBt', 'enterwebsite', 'website',
'password', 'websites', 'passwords', 'NewPasscode', 'NoneSavedYet', 'IncorrectAnswerMessage']
BUTTON_COLOR = "DodgerBlue4"
root = Tk()
BUTTON_FONT = tkfont.Font(family='Helvetica', size="20")
WELCOME_FONT = tkfont.Font(family='helvetica', size="40")
root.geometry("900x513")
root.wm_attributes('-transparent', True)
background = PhotoImage(file="BGImageLightTech.png")
canvas = Canvas(root, width=900, height=504)
counter = 0
LoggedIn = False
def init():
canvas.create_text(450, 200, text="Welcome to Password Saver!\nHere, you can save passwords\nand"
" access them with\nthe press of a button!",
font=WELCOME_FONT, fill='#00008B', tags='label1')
global curs, database
database = sqlite3.connect("hackathon_database.db")
curs = database.cursor()
curs.execute("""CREATE TABLE IF NOT EXISTS users_answers
(
question text,
answer text)""")
curs.execute("""CREATE TABLE IF NOT EXISTS users
(
name text,
code text
)""")
query = """CREATE TABLE IF NOT EXISTS users_joins
(user_id integer references users,
answers_id integer references users_answers)
"""
curs.execute(query)
start()
def createacc():
clearCanvas([])
canvas.create_text(450, 100, text='Create New Account', font=('Helvetica', 40), fill='#00008B', tags="label1")
canvas.create_text(450, 200, text='Enter Your Name', font=('Helvetica', 20), fill='#00008B', tags="label2")
name_entry = Entry(root)
canvas.create_window(450, 300, window=name_entry, tags="name_entry")
name_entry.config(highlightbackground='black')
def EnterName():
name = name_entry.get().strip()
if name == '':
canvas.create_text(450, 350, text='please enter a name in the field above',
font=('Helvetica', 20), tags='invalid_name')
return
got_a_unique_code = False
while not got_a_unique_code:
code = code_generator()
curs.execute("SELECT * FROM users WHERE code = :code", {'code': code})
result = curs.fetchall()
if not result:
with database:
curs.execute("INSERT INTO users VALUES (:name, :code)", {"name": name, "code": code})
user_id = curs.lastrowid
got_a_unique_code = True
clearCanvas([])
print(code)
canvas.create_text(450, 100, text='Your unique code is {}'.format(code), font=('Helvetica', 40),
fill='#00008B', tags='code_text')
canvas.create_text(450, 200, text='Please remember this, as all your saved passwords can only be viewe'
'd\nwhen you login in using your name and code. The code has been\n'
'printed in the console as well for you to copy.',
font=('Helvetica', 20), tags='code_warning')
def SecuritySetExlp():
clearCanvas([])
canvas.create_text(450, 100, text="Since this is your first time using this program,\n"
"you will need to set up some security questions",
font=('Helvetica', 40),
fill='#00008B', tags='code_text')
canvas.create_text(450, 200, text="Click the drop-down menu to\n"
"select a question you want to answer",
font=('Helvetica', 20),
fill='#00008B', tags='code_text')
canvas.create_text(450, 300, text="Make sure you answer at least 2!",
font=('Helvetica', 20),
fill='#00008B', tags='code_text')
def SetSecurityQ():
clearCanvas([])
variable = StringVar(root)
variable.set(questions[0])
sqmenu = OptionMenu(root, variable, *questions)
canvas.create_window(450, 200, window=sqmenu, tags='sqmenu')
def AskAnswer():
clearCanvas([])
q = variable.get().strip()
sqanswer = Entry(root)
canvas.create_window(450, 300, window=sqanswer, tags='sqanswer')
updated_list(questions, q)
def SetAnswer():
answer = sqanswer.get()
with database:
curs.execute("INSERT INTO users_answers VALUES (:question, :answer)",
{"question": q, "answer": answer.lower()})
last_id_answer = curs.lastrowid
curs.execute("INSERT INTO users_joins VALUES (:user_id, :answers_id)",
{"user_id": user_id, "answers_id": last_id_answer})
SetSecurityQ()
set_answer = Button(text="Set As Answer", command=SetAnswer)
canvas.create_window(400, 350, window=set_answer, tags='set_answer')
def CreateAccEnd():
if len(questions) > 5:
SetSecurityQ()
else:
for i in CLEAR_ALL:
canvas.delete(i)
canvas.create_text(450, 100, text="Great! You're all set now.", font=WELCOME_FONT,
tags='CreateAccEndMessage1')
canvas.create_text(450, 200, text="You can go login and begin your journey of havi"
"ng\nto remember only one password from now.",
font=('Helvetica', 20),
tags='CreateAccEndMessage2')
done = Button(text='Done', command=CreateAccEnd)
canvas.create_window(480, 350, window=done, tags='done')
select = Button(text='Select', command=AskAnswer)
canvas.create_window(420, 350, window=select, tags='select')
start()
next2 = Button(text='Next', command=SetSecurityQ)
canvas.create_window(450, 350, window=next2, tags='next2')
next1 = Button(text='Next', command=SecuritySetExlp)
canvas.create_window(450, 350, window=next1, tags='next1')
enter_name = Button(text='Enter', command=EnterName)
canvas.create_window(520, 300, window=enter_name, tags='enter_name')
def home():
if LoggedIn is False:
clearCanvas([])
canvas.create_text(450, 200, text="Welcome to Password Saver!\nHere, you can save passwords\nand"
" access them with\nthe press of a button!",
font=WELCOME_FONT, fill='#00008B', tags="welcome_text")
elif LoggedIn is True:
clearCanvas(['home'])
Logout = Button(root, text='Logout',
fg='black',
bd=10, highlightthickness=4,
highlightcolor=BUTTON_COLOR,
highlightbackground=BUTTON_COLOR,
borderwidth=4,
font=BUTTON_FONT,
command=start)
Logout_canvas = canvas.create_window(70, 5,
anchor="nw",
window=Logout, tags='logout')
users_powers(code)
def logout():
LoggedIn = False
clearCanvas([])
start()
def login():
clearCanvas([])
canvas.create_text(450, 100, text='Login', font=('Helvetica', 40), fill='#00008B', tags="label1")
canvas.create_text(450, 200, text='Enter Your Code', font=('Helvetica', 20), fill='#00008B', tags="label2")
code_entry = Entry(root)
canvas.create_window(450, 300, window=code_entry, tags="code_entry")
code_entry.config(highlightbackground='black')
def EnterCode():
global result, code, LoggedIn
code = code_entry.get().strip()
curs.execute("SELECT * FROM users WHERE code =:code", {'code': code})
result = curs.fetchall()
if result:
code = result[0][1]
clearCanvas([])
curs.execute("SELECT rowid FROM users WHERE code = :code", {"code": code})
id_of_our_user = curs.fetchall()[0][0]
curs.execute("SELECT answers_id FROM users_joins WHERE user_id = :id_of_our_user",
{"id_of_our_user": id_of_our_user})
answer_ids = curs.fetchall()
canvas.create_text(450, 200, text="You will only be logged in if you\n"
"answer your security questions correctly.", font=('Helvetica', 40),
fill="#00008B", tags="broad_security")
global counter, ids
if counter == 0:
clearCanvas(['broad_security'])
ids = answer_ids[random.randint(0, len(answer_ids) - 1)]
qid = ids[0]
curs.execute("SELECT * FROM users_answers WHERE rowid = :qid", {"qid": qid})
question_answer_is = curs.fetchone()
canvas.create_text(450, 300, text="Answer the security question: {}".format(question_answer_is[0]),
font=('Helvetica', 20),
fill="#00008B", tags="spec_security")
ans_entry1 = Entry(root)
canvas.create_window(450, 350, window=ans_entry1, tags='ans_entry')
def verifyQ1():
clearCanvas([])
global counter
given_ans = ans_entry1.get()
if given_ans.lower() == question_answer_is[1].lower():
counter += 1
EnterCode()
else:
canvas.create_text(450, 200, text='Wrong Answer; your login attempt has failed', font=('Helveti'
'ca', 40)
, fill='#FF0000', tags='IncorrectAnswerMessage')
canvas.create_text(450, 250, text='Please Try Again', font=('Helvetica', 20)
, fill='#FF0000', tags='IncorrectAnswerMessage')
enter_secq1 = Button(text='Enter', command=verifyQ1)
canvas.create_window(520, 350, window=enter_secq1, tags='enter_secq')
if counter == 1:
clearCanvas(['broad_security'])
ids2 = answer_ids[random.randint(0, len(answer_ids) - 1)]
while ids2 == ids:
ids2 = answer_ids[random.randint(0, len(answer_ids) - 1)]
qid = ids2[0]
curs.execute("SELECT * FROM users_answers WHERE rowid = :qid", {"qid": qid})
question_answer_is = curs.fetchone()
canvas.create_text(450, 300, text="Answer the security question: {}".format(question_answer_is[0]),
font=('Helvetica', 20),
fill="#00008B", tags="spec_security")
ans_entry2 = Entry(root)
canvas.create_window(450, 350, window=ans_entry2, tags='ans_entry')
def verifyQ2():
clearCanvas([])
global counter
given_ans = ans_entry2.get()
if given_ans.lower() == question_answer_is[1]:
counter += 1
EnterCode()
else:
counter = 0
canvas.create_text(450, 200, text='Wrong Answer; your login attempt has failed', font=('Helveti'
'ca', 40)
, fill='#FF0000', tags='IncorrectAnswerMessage')
canvas.create_text(450, 250, text='Please Try Again', font=('Helvetica', 20)
, fill='#FF0000', tags='IncorrectAnswerMessage')
enter_secq2 = Button(text='Enter', command=verifyQ2)
canvas.create_window(520, 350, window=enter_secq2, tags='enter_secq')
if counter == 2:
LoggedIn = True
canvas.delete('login', 'createacc')
Logout = Button(root, text='Logout',
fg='black',
bd=10, highlightthickness=4,
highlightcolor=BUTTON_COLOR,
highlightbackground=BUTTON_COLOR,
borderwidth=4,
font=BUTTON_FONT,
command=logout)
Logout_canvas = canvas.create_window(70, 5,
anchor="nw",
window=Logout, tags='logout')
counter = 0
clearCanvas([])
query = """CREATE TABLE IF NOT EXISTS {}
(
website text,
password text
)""".format(code
)
curs.execute(query)
users_powers(
code)
else:
clearCanvas([])
canvas.create_text(450, 100, text="This code is not valid",
font=('Helvetica', 40),
fill="#00008B", tags="invalid_code_message")
canvas.create_text(450, 200, text="Create a new account to join",
font=('Helvetica', 20),
fill="#00008B", tags="createacc_invalid_message")
enter = Button(text='Enter', command=EnterCode)
canvas.create_window(520, 300, window=enter, tags='enter')
def users_powers(table_name):
clearCanvas([])
canvas.create_text(450, 100, text="You are now logged in as {}".format(result[0][0]),
font=('Helvetica', 40), fill='#00008B', tags='LoggedInMessage')
canvas.create_text(450, 200, text="You can now view your passwords or create a new one",
font=('Helvetica', 20), fill='#00008B', tags='ViewPasswordMessage')
def Save():
save_a_password(code)
SaveButton = Button(text='New +', command=Save)
canvas.create_window(400, 250, window=SaveButton, tags='save')
def Search():
search_for_a_password(code)
SearchButton = Button(text='View', command=Search)
canvas.create_window(500, 250, window=SearchButton, tags='search')
def save_a_password(table_name):
clearCanvas([])
website_entry = Entry(root)
canvas.create_window(450, 200, window=website_entry, tags='savewebsite')
canvas.create_text(450, 150, text="The name of the website (Enter like Facebook, Google, Youtube, meaning only the"
" first letter capital and no urls): ", font=('Helvetica', 15),
tags='WebsiteNameMessage')
def SavePass():
website = website_entry.get()
curs.execute("SELECT * FROM {} WHERE website=:website".format(table_name), {"website": website})
result = curs.fetchall()
if not result == []:
canvas.create_text(450, 250, text="Your already have a password saved for this website.\n",
font=('Helvetica', 15), tags='AlreadySavedMessage')
def saveAnyway():
password_entry = Entry(root)
canvas.create_window(450, 400, window=password_entry, tags='savepassword1')
canvas.create_text(450, 350, text="Enter the password you want to save",
font=('Helvetica', 15), tags='EnterPasswordMessage1')
def savePasswordAnyway():
password = password_entry.get()
with database:
curs.execute("INSERT INTO {} VALUES (:website, :password)".format(table_name),
{"website": website, "password": password})
canvas.create_text(450, 400, text='Your password has been saved. It will show up when you search fo'
'r the passwords.',
font=('Helvetica', 15), tags='PasswordSavedMessage')
def Return():
users_powers(code)
def New():
save_a_password(code)
def View():
search_for_a_password(code)
retrn = Button(text='Return to Profile', command=Return)
canvas.create_window(300, 450, window=retrn, tags='retrn')
new = Button(text='New+', command=New)
canvas.create_window(400, 450, window=new, tags='new')
view = Button(text='View Passwords', command=View)
canvas.create_window(500, 450, window=view, tags='view')
savePasswordAnywayBt = Button(text='Enter', command=savePasswordAnyway)
canvas.create_window(513, 350, window=savePasswordAnywayBt, tags="savePasswordAnywayBt")
saveAnywayBt = Button(text='Save For Different Account', command=saveAnyway)
canvas.create_window(350, 300, window=saveAnywayBt, tags="saveAnywayBt")
def SearchInstead():
search_for_a_password(table_name)
SearchInsteadBt = Button(text='Search for Password', command=SearchInstead)
canvas.create_window(550, 300, window=SearchInsteadBt, tags="SearchInsteadBt")
else:
password_entry = Entry(root)
canvas.create_window(450, 300, window=password_entry, tags='savepassword2')
canvas.create_text(450, 250, text="Enter the password you want to save",
font=('Helvetica', 15), tags='EnterPasswordMessage2')
def savePassword():
password = password_entry.get()
with database:
curs.execute("INSERT INTO {} VALUES (:website, :password)".format(table_name),
{"website": website, "password": password})
canvas.create_text(450, 350,
text='Your password has been saved. It will show up when you search for the passwo'
'rds.',
font=('Helvetica', 15), tags='savedmessage')
def Return():
users_powers(code)
def New():
save_a_password(code)
def View():
search_for_a_password(code)
retrn = Button(text='Return to Profile', command=Return)
canvas.create_window(300, 450, window=retrn, tags='retrn')
new = Button(text='New+', command=New)
canvas.create_window(400, 450, window=new, tags='new')
view = Button(text='View Passwords', command=View)
canvas.create_window(500, 450, window=view, tags='view')
savePasswordBt = Button(text='Enter', command=savePassword)
canvas.create_window(513, 300, window=savePasswordBt, tags='savePasswordBt')
enterWeb = Button(text='Enter', command=SavePass)
canvas.create_window(513, 200, window=enterWeb, tags='enterwebsite')
def search_for_a_password(table_name):
clearCanvas([])
curs.execute("SELECT * FROM {}".format(table_name))
result = curs.fetchall()
if not result:
clearCanvas([])
canvas.create_text(450, 200, text="You don't have any passwords saved yet.", font=('Helvetica', 20),
fill='#00008B', tags='NoneSavedYet')
def New():
save_a_password(code)
new = Button(text="New +", command=New)
canvas.create_window(450, 250, window=new, tags='NewPasscode')
else:
clearCanvas([])
canvas.create_text(200, 100, text="Websites", font=('Helvetica', 40),
fill='#00008B', tags='website')
canvas.create_text(700, 100, text="Passwords", font=('Helvetica', 40),
fill='#00008B', tags='password')
y_coord = 150
for tups in result:
canvas.create_text(200, y_coord, text=str(tups[0]), font=('Helvetica', 20),
fill='#00008B', tags='websites')
canvas.create_text(700, y_coord, text=str(tups[1]), font=('Helvetica', 20),
fill='#00008B', tags='passwords')
y_coord += 50
def Return():
users_powers(code)
def New():
save_a_password(code)
retrn = Button(text='Return to Profile', command=Return)
canvas.create_window(300, 450, window=retrn, tags='retrn')
new = Button(text='New+', command=New)
canvas.create_window(400, 450, window=new, tags='new')
def update_a_password(table_name):
pass
def code_generator():
letters = string.ascii_lowercase
result_str = ''.join(random.choice(letters) for i in range(12))
return result_str
def select_security_questions(updated_q):
q1 = 1
q2 = 1
while q1 == q2:
q1 = random.randint(0, len(updated_q) - 1)
q2 = random.randint(0, len(updated_q) - 1)
return [updated_q[q1], updated_q[q2]]
def updated_list(questions, question_used):
Questions_Updated = questions
Questions_Updated.remove(question_used)
return Questions_Updated
def clearCanvas(exceptions):
for i in CLEAR_ALL:
if i in exceptions:
pass
else:
canvas.delete(i)
def start():
global Home, Login, CreateAcc
canvas.pack(fill="both", expand=True)
canvas.create_image(0, 0, image=background,
anchor="nw")
Home = Button(root, text='Home',
fg='black',
bd=10, highlightthickness=4,
highlightcolor=BUTTON_COLOR,
highlightbackground=BUTTON_COLOR,
borderwidth=4,
font=BUTTON_FONT,
command=home)
Login = Button(root, text='Login',
fg='black',
bd=10, highlightthickness=4,
highlightcolor=BUTTON_COLOR,
highlightbackground=BUTTON_COLOR,
borderwidth=4,
font=BUTTON_FONT,
command=login)
CreateAcc = Button(root, text='Create Account',
fg='black',
bd=10, highlightthickness=4,
highlightcolor=BUTTON_COLOR,
highlightbackground=BUTTON_COLOR,
borderwidth=4,
font=BUTTON_FONT,
command=createacc)
Home_canvas = canvas.create_window(5, 5,
anchor="nw",
window=Home, tags='home')
Login_canvas = canvas.create_window(70, 5,
anchor="nw",
window=Login, tags='login')
CreateAcc_canvas = canvas.create_window(130, 5,
anchor="nw",
window=CreateAcc, tags='createacc')
root.mainloop()
QUIT = Button(root, text="Exit Program", command=root.quit)
QUIT.pack()
root.mainloop()
if __name__ == '__main__':
init()