-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathGUI_main_lite.py
663 lines (549 loc) · 33.3 KB
/
GUI_main_lite.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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
import os
import string
import csv
import tabulate # pretty print, optional dependency
import customtkinter
from tkinter import StringVar
import tkinter.messagebox
customtkinter.set_appearance_mode("System") # Modes: "System" (standard), "Dark", "Light"
customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "green", "dark-blue"
ALPHABET = string.ascii_letters + string.digits
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
#----------------------------------------GUI---------------------------
# configure window
self.title("MYP manager")
self.geometry(f"{1100}x{580}")
# configure grid layout (4x4)
self.grid_columnconfigure(1, weight=1)
self.grid_columnconfigure((2, 3), weight=0)
self.grid_rowconfigure((0, 1, 2), weight=1)
# create footer frame
self.footer_frame = customtkinter.CTkFrame(self, height=25,corner_radius=0, fg_color="#007ACC")
self.footer_frame.grid(row=3, column=1,padx=0, pady=(5, 0), sticky="ew")
self.footer_frame.grid_columnconfigure(0, weight=1)# center, fill space
self.footer_label = customtkinter.CTkLabel( master=self.footer_frame, text="Developed by Abhijeetbyte © 2024",text_color=("#FFFFFF"),font=customtkinter.CTkFont(size=12),justify="center" )
self.footer_label.grid(row=0, column=0,sticky="nsew")
# create side frame
self.sidebar_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0)
self.sidebar_frame.grid(row=0, column=0, rowspan=5, sticky="nsew")
self.sidebar_frame.grid_rowconfigure(5, weight=1)
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_frame, text="Appearance Mode:", anchor="w")
self.appearance_mode_label.grid(row=7, column=0, padx=20, pady=(10, 0))
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_frame, values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
self.appearance_mode_optionemenu.grid(row=8, column=0, padx=20, pady=(10, 10))
# create welcome frame
self.welcome_frame = customtkinter.CTkFrame(self)
self.welcome_frame.grid(row=1, column=1, sticky="ns")
self.welcome_label = customtkinter.CTkLabel(self.welcome_frame, justify="left", text="\n Welcome ! \n\n THIS APPLICATION USES A MASTER PASSWORD\
\n TO ENCRYPT & DECRYPT YOUR DATA.\
\n USE ANY ALPHANUMERIC PASSWORD (RECOMMENDED)\
\n AND REMEMBER THAT.\
\n\n WARNING: IF YOU LOSE YOUR MASTER PASSWORD, THEN YOU\
\n WILL NOT BE ABLE TO RECOVER YOUR SAVED PASSWORDS.\
\n\n VISIT: https://github.com/Abhijeetbyte/MYPmanager", font=customtkinter.CTkFont(size=14))
self.welcome_label.grid(row=0, column=0, padx=(20,0), pady=(20, 30))
self.welcome_button = customtkinter.CTkButton(self.welcome_frame, text="Next", command=self.welcome_button_event, width=200)
self.welcome_button.grid(row=3, column=0, padx=30, pady=(15, 15))
# create login frame
self.login_frame = customtkinter.CTkFrame(self)
self.login_frame.grid(row=1, column=1, sticky="ns")
self.login_label = customtkinter.CTkLabel(self.login_frame, text="MYP manager\n\n",
font=customtkinter.CTkFont(size=20, weight="bold"))
self.login_label.grid(row=0, column=0, padx=150, pady=(50, 100))
self.masterpassword_entry = customtkinter.CTkEntry(master=self.login_frame, width=300,height=40,border_width=1, show="*", placeholder_text=" ENTER MASTER PASSWORD")
self.masterpassword_entry.grid(row=2, column=0, padx=30, pady=(0, 15))
self.login_label2 = customtkinter.CTkLabel(self.login_frame, text="( Must have a minimum of 8 characters )")
self.login_label2.grid(row=3, column=0, padx=20, pady=(5, 5))
self.login_button = customtkinter.CTkButton(self.login_frame, text="Submit", command=self.login_button_event, width=200)
self.login_button.grid(row=4, column=0, padx=30, pady=(30, 30))
# create sidebar frame with widgets and buttons
self.sidebar_button_frame = customtkinter.CTkFrame(self, width=140, corner_radius=0)
self.sidebar_button_frame.grid(row=0, column=0, rowspan=5, sticky="nsew")
self.sidebar_button_frame.grid_rowconfigure(5, weight=1)
self.logo_label = customtkinter.CTkLabel(self.sidebar_button_frame, text="Select Option: ", font=customtkinter.CTkFont(size=20, weight="bold"))
self.logo_label.grid(row=0, column=0, padx=20, pady=(20, 10))
self.sidebar_button_1 = customtkinter.CTkButton(self.sidebar_button_frame, text="Add New", command=self.add_button_event)
self.sidebar_button_1.grid(row=1, column=0, padx=20, pady=10)
self.sidebar_button_2 = customtkinter.CTkButton(self.sidebar_button_frame,text="Search", command=self.search_button_event)
self.sidebar_button_2.grid(row=2, column=0, padx=20, pady=10)
self.sidebar_button_3 = customtkinter.CTkButton(self.sidebar_button_frame, text="Edit", command=self.edit_button_event)
self.sidebar_button_3.grid(row=3, column=0, padx=20, pady=10)
self.sidebar_button_4 = customtkinter.CTkButton(self.sidebar_button_frame, text="Delete", command=self.delete_button_event)
self.sidebar_button_4.grid(row=4, column=0, padx=20, pady=10)
self.sidebar_button_4 = customtkinter.CTkButton(self.sidebar_button_frame, text="Back", command=self.back_button_event)
self.sidebar_button_4.grid(row=6, column=0, padx=20, pady=(10, 0))
self.appearance_mode_label = customtkinter.CTkLabel(self.sidebar_button_frame, text="Appearance Mode:", anchor="w")
self.appearance_mode_label.grid(row=7, column=0, padx=20, pady=(10, 0))
self.appearance_mode_optionemenu = customtkinter.CTkOptionMenu(self.sidebar_button_frame, values=["Light", "Dark", "System"],
command=self.change_appearance_mode_event)
self.appearance_mode_optionemenu.grid(row=8, column=0, padx=20, pady=(10, 10))
# create main entry field and button
self.entry_frame = customtkinter.CTkFrame(self,width=250)
self.entry_frame.grid(row=0, column=1,padx=(20,0),pady=(20,0), sticky="nsew")
self.entry_label = customtkinter.CTkLabel(self.entry_frame, text="Add your credentials: ", font=customtkinter.CTkFont(size=16))
self.entry_label.grid(row=0, column=1, padx=20, pady=(20, 10))
self.label_name = customtkinter.CTkLabel(self.entry_frame, text="ENTER URL OR APP NAME, YOU WANT TO SAVE: ",justify="right",anchor="e",width=350, font=customtkinter.CTkFont(size=14))
self.label_name.grid(row=1, column=0, padx=(20,5), pady=(5, 5))
self.entry_name = customtkinter.CTkEntry(master=self.entry_frame,width=350,height=40,border_width=1)
self.entry_name.grid(row=1, column=1, padx=5, pady=(5, 5))
self.label_uname = customtkinter.CTkLabel(self.entry_frame, text="ENTER NAME/USERNAME, YOU WANT TO SAVE: ",justify="right",anchor="e",width=350, font=customtkinter.CTkFont(size=14))
self.label_uname.grid(row=2, column=0, padx=(20,5), pady=(5, 5))
self.entry_uname = customtkinter.CTkEntry(master=self.entry_frame, width=350,height=40,border_width=1)
self.entry_uname.grid(row=2, column=1, padx=5, pady=(5, 5))
self.label_password = customtkinter.CTkLabel(self.entry_frame, text="ENTER PASSWORD, YOU WANT TO SAVE: ",justify="right",anchor="e",width=350, font=customtkinter.CTkFont(size=14))
self.label_password.grid(row=3, column=0, padx=(20,20), pady=(5, 5))
self.entry_password = customtkinter.CTkEntry(master=self.entry_frame,width=350,height=40,border_width=1, show="*")
self.entry_password.grid(row=3, column=1, padx=5, pady=(5, 5))
self.entry_button = customtkinter.CTkButton(self.entry_frame, text="Submit") #entry field submit button, no initial command
self.entry_button.grid(row=4, column=1, padx=30, pady=(10, 10))
# create textbox
self.textbox = customtkinter.CTkTextbox(self, width=400,
border_width=1,
border_color="#007ACC",
scrollbar_button_color="#007ACC",
wrap="none", # allow horizontal scroll
font=("Courier", 16)) #Monospaced font
self.textbox.grid(row=1, column=1,padx=(20, 0), pady=(20, 0), sticky="nsew")
# create horizontal scrollbar
self.h_scrollbar = customtkinter.CTkScrollbar(self, orientation="horizontal",button_color="#007ACC", command=self.textbox.xview)
self.h_scrollbar.grid(row=2, column=1, sticky="ew", padx=(20, 0), pady=(0, 5))
self.textbox.configure(xscrollcommand=self.h_scrollbar.set)
# set default values
self.appearance_mode_optionemenu.set("Light")
self.textBox(text='') # text box (clear)
data_file = os.path.isfile('data.csv')#check whether data file is there or not
if not data_file: # if csv not found
self.create_csv() # call function and create csv
self.welcome_event()# start with welcome frame
else :
self.login_event()#start with login frame
#-------------------------------------GUIOperation----------------------------
def welcome_event(self): #bundel
#Show only the welcome frame, by removing everything else
print("Welcome \n")
self.login_frame.grid_forget()
self.sidebar_button_frame.grid_forget()
self.entry_frame.grid_forget()
self.textbox.grid_forget()
self.h_scrollbar.grid_forget()
def login_event(self): #bundel
# Show only the login frame
print("Login \n")
self.welcome_frame.grid_forget()# forget frame
self.sidebar_button_frame.grid_forget()# forget frame
self.entry_frame.grid_forget()# forget frame
self.textbox.grid_forget()# forget frame
self.h_scrollbar.grid_forget()
self.login_frame.grid(row=1, column=1, sticky="ns") # show login frame
def main_event(self): #bundel
print("Main menu\n")
self.welcome_frame.grid_forget()# forget frame (make sure)
self.login_frame.grid_forget() # forget frame (make sure)
self.sidebar_button_frame.grid(row=0, column=0, rowspan=5, sticky="nsew")# show frame
self.entry_frame.grid(row=0, column=1,padx=(20,0),pady=(20,0), sticky="nsew")# show frame
self.textbox.grid(row=1, column=1, padx=(20, 0), pady=(20, 0), sticky="nsew")# show frame
self.h_scrollbar.grid(row=2, column=1, sticky="ew", padx=(20, 0), pady=(0, 20))
self.add_button_event() # start with add menu
def welcome_button_event(self):
print("Next button pressed\n")
self.login_event()
def change_appearance_mode_event(self, new_appearance_mode: str):
print("Appearance changed :" , new_appearance_mode)
customtkinter.set_appearance_mode(new_appearance_mode)
def login_button_event(self):
print("Login button pressed\n")
login_status = self.login_menu_op()# call, for check
if login_status:
self.main_event()#call main window function
else:
self.login_event() #do not preceded,repet
self.masterpassword_entry.delete(0,'end') #clear entry field
def back_button_event(self):
print("Back button pressed\n")
self.login_event() # call function to start with login window
# clear entry field
self.masterpassword_entry.delete(0,'end')# clear
self.entry_name.delete(0, 'end')
self.entry_uname.delete(0, 'end')
self.entry_name.delete(0, 'end')
self.textBox(text='') # text box (clear)
def add_button_event(self):
print("Add button pressed\n")
self.entry_label.configure(text="Add your credentials: ")#label
self.label_name.grid(row=1, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_uname.grid(row=2, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_password.grid(row=3, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO SAVE: ")#changelabel
self.label_uname.configure(text="ENTER NAME/USERNAME, YOU WANT TO SAVE: ")#change label
self.label_password.configure(text="ENTER PASSWORD, YOU WANT TO SAVE")#change label
self.entry_password.grid(row=3, column=1, padx=20, pady=(5, 5))# add (make sure)
self.entry_uname.grid(row=2, column=1, padx=20, pady=(5, 5))# add
# clear entry field
self.entry_name.delete(0, 'end')
self.entry_uname.delete(0, 'end')
self.entry_password.delete(0, 'end')
self.textBox(text='') # clear box
self.entry_button.configure(command=self.add_menu_op) # call this function, when submit button is pressed
def search_button_event(self):
print("Search button pressed\n")
self.entry_label.configure(text="Search your credentials: ")#label
self.label_uname.grid_forget()#remove
self.label_password.grid_forget()#remove
self.entry_uname.grid_forget()# remove
self.entry_password.grid_forget()# remove
# clear entry field
self.entry_name.delete(0, 'end')
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO SEARCH: ")#configure the label text
print("HINT: Clicking the submit button will show all saved credentials.\n")
self.textBox("HINT: Clicking the submit button will show all saved credentials")
self.entry_button.configure(command=self.search_menu_op) # call this function, when submit button is pressed
def edit_button_event(self):
print("Edit button pressed\n")
self.entry_label.configure(text="Edit your credentials: ")#label
self.label_uname.grid_forget()#remove
self.label_password.grid_forget()#remove
self.entry_uname.grid_forget()#remove
self.entry_password.grid_forget()#remove
# clear entry field
self.entry_name.delete(0, 'end')
self.entry_uname.delete(0, 'end')
self.entry_password.delete(0, 'end')
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO EDIT: ")#configure the label text
print("HINT: Clicking the submit button will show all saved credentials.\n")
self.textBox("HINT: Clicking the submit button will show all saved credentials")
self.entry_button.configure(command=self.edit_menu_op) # call this function, when submit button is pressed
def delete_button_event(self):
print("Delete button pressed\n")
self.entry_label.configure(text="Delete your credentials: ")#label
self.label_uname.grid_forget()#remove
self.label_password.grid_forget()#remove
self.entry_uname.grid_forget()#remove
self.entry_password.grid_forget()#remove
# clear entry field
self.entry_name.delete(0, 'end')
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO DELETE: ")#configure the label text
print("HINT: Clicking the submit button will show all saved credentials.\n")
self.textBox("HINT: Clicking the submit button will show all saved credentials")
self.entry_button.configure(command=self.delete_menu_op) # call this function, when submit button is pressed
#----------------------------------MenuOperation----------------------------------
def login_menu_op(self):
master_pass = self.masterpassword_entry.get() #fetch from entry box
print("Checked master password: ", master_pass,'\n')
if len(master_pass) >= 8: #if sucessfull, then move to main window
return master_pass
else:
return False
print("WARNING: Master password must be at least 8 characters long\n")
#pass
def add_menu_op(self): #when, entry button is presed under Add menu
print("Operation : Add\n")
nameVariable = self.entry_name.get() # fetch entry box inputs
unameVariable = self.entry_uname.get()
passwordVariable = self.entry_password.get()
masterpassVariable = self.login_menu_op() #call function, fetch
print("Adding: ",nameVariable,",",unameVariable,",", passwordVariable)
print("With: ",masterpassVariable,"\n")
if (unameVariable == ''): # if found empty, replace it by 'Unavailable' label
unameVariable = 'UNAVAILABLE'
if (passwordVariable == ''):
passwordVariable = 'UNAVAILABLE'
if (nameVariable == ''): # URL/App name
print("WARNING: URL or App Name cannot be empty.\n")
self.textBox("WARNING : URL or App Name cannot be empty.")
else:
encrypted_pass = self.encrypt(passwordVariable, masterpassVariable)# call encrypt function to encrypt password
self.add(unameVariable, encrypted_pass, nameVariable)# call function to add user data
#clear entry box
self.entry_uname.delete(0,'end')
self.entry_name.delete(0,'end')
self.entry_password.delete(0,'end')
self.entry_button.configure(command=self.add_menu_op) # call this function, when submit button is pressed
def search_menu_op(self):
print("Operation : Search\n")
nameVariable = self.entry_name.get() # fetch entry box inputs
masterpassVariable = self.login_menu_op() #call function, fetch
print("Searching: ",nameVariable)
print("With: :",masterpassVariable , "\n")
show_result = self.search(masterpassVariable,nameVariable)# call function
show_tabulate = tabulate.tabulate(show_result, headers='keys', tablefmt='pipe', showindex=False)#Pretty Print
self.textBox(show_tabulate) # print in textbox area
#print(show_tabulate)
#clear entry box
self.entry_name.delete(0,'end')
self.entry_button.configure(command=self.search_menu_op) # call this function, when submit button is pressed
def edit_menu_op(self):
print("Operation: Edit\n")
nameVariable = self.entry_name.get() # fetch entry box inputs
masterpassVariable = self.login_menu_op() # call function, fetch
print("Searching: ", nameVariable)
print("With: ", masterpassVariable, "\n")
show_result = self.search(masterpassVariable, nameVariable) # call search function
print(show_result,"\n")
show_tabulate = tabulate.tabulate(show_result, headers='keys', tablefmt='pipe', showindex=False) # Pretty Print
self.textBox(show_tabulate) # print in textbox area
if len(show_result) > 1: # multiple credentials found, len = rows
print("Multiple credentials found, going for index\n")
self.label_name.configure(text="ENTER AN INDEX VALUE, YOU WANT TO EDIT: ")#change label
self.entry_button.configure(command=lambda: self.edit_multi_index(show_result, masterpassVariable)) # call this function, to handle indexes, when submit button is pressed
else:
print("Single credential found\n")
indexVariable = show_result[0]['Index'] # extract the index( take default index)
print("Default Index input:", indexVariable, "\n")
self.entry_uname.grid(row=2, column=1, padx=20, pady=(5, 5)) # add
self.entry_password.grid(row=3, column=1, padx=20, pady=(5, 5)) # add
self.label_uname.grid(row=2, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_password.grid(row=3, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_uname.configure(text="ENTER NEW NAME/USERNAME: ")#change label
self.label_password.configure(text="ENTER NEW PASSWORD: ")#change label
self.entry_button.configure(command=lambda: self.edit_new_input(show_result, masterpassVariable, indexVariable)) # call this function, to handle indexes, when submit button is pressed
def edit_multi_index(self, show_result, masterpassVariable): #part of edit_menu_op()
print("Operation: Edit Index \n")
indexVariable = self.entry_name.get() # fetch index input
print("Index input:", indexVariable, "\n")
if indexVariable: # not empty
indexVariable = int(indexVariable)
self.entry_uname.grid(row=2, column=1, padx=20, pady=(5, 5)) # add
self.entry_password.grid(row=3, column=1, padx=20, pady=(5, 5)) # add
self.label_uname.grid(row=2, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_password.grid(row=3, column=0, padx=(20,5), pady=(5, 5)) #add label
self.label_uname.configure(text="ENTER NEW NAME/USERNAME: ")#change label
self.label_password.configure(text="ENTER NEW PASSWORD: ")#change label
self.entry_button.configure(command=lambda: self.edit_new_input(show_result, masterpassVariable, indexVariable)) # call this function, to handle indexes, when submit button is pressed
def edit_new_input(self, show_result, masterpassVariable, indexVariable): #part of edit_menu_op()
new_uameVariable = self.entry_uname.get() # fetch entry box input
new_passwordVariable = self.entry_password.get() # fetch entry box input
# exception
if not new_uameVariable:
old_name = show_result[0]['Username'] #old username
new_uameVariable = old_name
if not new_passwordVariable:
old_password = show_result[0]['Password'] #old username
new_passwordVariable = old_password
print("New Username:", new_uameVariable, ", New Password:", new_passwordVariable,"\n")
new_passwordVariable = self.encrypt(new_passwordVariable, masterpassVariable) # call function, to encrypted
self.edit(indexVariable, new_uameVariable, new_passwordVariable) # call edit function
# clear entry field
self.entry_uname.delete(0, 'end')
self.entry_name.delete(0, 'end')
self.entry_password.delete(0, 'end')
self.label_uname.grid_forget()#remove
self.label_password.grid_forget()#remove
self.entry_uname.grid_forget()#remove
self.entry_password.grid_forget()#remove
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO EDIT: ")#configure the label text
self.entry_button.configure(command=self.edit_menu_op) # call this function, when submit button is pressed
def delete_menu_op(self):
print("Operation: Delete\n")
nameVariable = self.entry_name.get() # fetch entry box inputs
masterpassVariable = self.login_menu_op() # call function, fetch
print("Searching: ", nameVariable)
print("With: ", masterpassVariable, "\n")
show_result = self.search(masterpassVariable, nameVariable) # call search function
show_tabulate = tabulate.tabulate(show_result, headers='keys', tablefmt='pipe', showindex=False) # Pretty Print
self.textBox(show_tabulate) # print in textbox area
if len(show_result) > 1: # multiple credentials found, len = rows
print("Multiple credentials found, going for index\n")
self.label_name.configure(text="ENTER AN INDEX VALUE, YOU WANT TO DELETE: ")#change label
self.entry_button.configure(command=lambda: self.delete_multi_index(show_result, masterpassVariable)) # call this function, to handle indexes, when submit button is pressed
else:
print("Single credential found\n")
indexVariable = show_result[0]['Index'] # Extract the index from the first result( take default index)
print("Default Index input:", indexVariable, "\n")
self.delete_dialog = customtkinter.CTkInputDialog(text="Type 'Yes' to confirm delete", title="Do you want to delete?")
confirm = self.delete_dialog.get_input()
print("Confirm: " ,confirm)
if confirm in ["Yes", "yes"]:
self.delete(indexVariable)# call delete function
else:
self.textBox("Delete Cancelled ")
# clear entry box
self.entry_name.delete(0, 'end')
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO DELETE: ")#configure the label text
def delete_multi_index(self, show_result, masterpassVariable): #part of edit_menu_op()
print("Operation: Edit Index \n")
indexVariable = self.entry_name.get() # fetch index input
print("Index input:", indexVariable, "\n")
if indexVariable: # not empty
indexVariable = int(indexVariable)
self.delete_dialog = customtkinter.CTkInputDialog(text="Type 'Yes' to confirm delete", title="Do you want to delete?")
confirm = self.delete_dialog.get_input()
print("Confirm: " ,confirm)
if confirm in ["Yes", "yes"]:
self.delete(indexVariable)# call delete function
else:
self.textBox("Delete Cancelled ")
# clear entry box
self.entry_name.delete(0, 'end')
self.label_name.configure(text="ENTER URL OR APP NAME, YOU WANT TO DELETE: ")#change label
self.entry_button.configure(command=self.delete_menu_op) # call this function, when submit button is pressed
#--------------------------------Backend-------------------------------------------
# Setting up the textbox to display messages
def textBox(self, text):
self.textbox.configure(state="normal")
self.textbox.delete("0.0", "end") # Clear
self.textbox.insert("0.0", text) # Add new text
self.textbox.configure(state="disabled")# Disable
# Creating a CSV file with headers
def create_csv(self):
# Open file for writing
with open('data.csv', mode='w', newline='') as file:
# Create a CSV writer
writer = csv.writer(file)
# Write headers
writer.writerow(['Index', 'Url/App name', 'Username', 'Password'])
print("CSV created\n")
# Encrypting a password using a master password
def encrypt(self, password, master_pass):
encrypted_password = "" # Start with an empty string for the encrypted password
# Loop through each character in the password
for i in range(len(password)):
# Calculate shift based on master password
shift = (ord(master_pass[i % len(master_pass)]) + i) % len(ALPHABET)
# If the character is in "ALPHABET"
if password[i] in ALPHABET:
# Find the new position after shifting
new_pos = (ALPHABET.find(password[i]) + shift) % len(ALPHABET)
# Append the encrypted character
encrypted_password += ALPHABET[new_pos]
else:
# Keep non-ALPHABET characters as they are
encrypted_password += password[i]
return encrypted_password
# Decrypting a password using a master password
def decrypt(self, encrypted_password, master_pass):
decrypted_password = "" # Start with an empty string for the decrypted password
# Loop through each character in the encrypted password
for i in range(len(encrypted_password)):
# Calculate shift based on master password
shift = (ord(master_pass[i % len(master_pass)]) + i) % len(ALPHABET)
# If the character is in "ALPHABET"
if encrypted_password[i] in ALPHABET:
# Find the original position after shifting
new_pos = (ALPHABET.find(encrypted_password[i]) - shift) % len(ALPHABET)
# Append the decrypted character
decrypted_password += ALPHABET[new_pos]
else:
# Keep non-ALPHABET characters as they are
decrypted_password += encrypted_password[i]
return decrypted_password
# Getting the index for the next entry in the CSV
def get_next_index(self):
try:
# Try opening the CSV file
with open('data.csv', mode='r') as file:
# Create a CSV reader
reader = csv.reader(file)
# Read all rows
rows = list(reader)
# If there are more than just the header row
if len(rows) > 1:
# Get the index from the last row and increment
last_index = int(rows[-1][0])
return last_index + 1
else:
# Start from index 1 if no data rows
return 1
file.close()# Close the file after writing
except FileNotFoundError:
# Start from index 1 if file not found
return 1
# Adding a new entry to the CSV
def add(self, name, encrypted_pass, url):
index = self.get_next_index() # Get the next available index
# Open CSV file for appending
with open('data.csv', mode='a', newline='') as file:
# Create a CSV writer
writer = csv.writer(file)
# Write the new entry
writer.writerow([index, url, name, encrypted_pass])
file.close()# Close the file after writing
print("Credentials Added Successfully.\n")
self.textBox("Credentials Added Successfully.\n")
self.backup() # Create a backup of the CSV
# Searching for entries in the CSV by URL/app name
def search(self, master_pass, url=''):
results = [] # Store search results here
# Open CSV file for reading
with open('data.csv', mode='r') as file:
# Create a CSV DictReader
reader = csv.DictReader(file)
# Iterate over each row
for row in reader:
# Check if URL/app name matches search query
if url.lower() in row['Url/App name'].lower():
# Decrypt password and append row to results
row['Password'] = self.decrypt(row['Password'], master_pass)
results.append(row)
file.close()# Close the file after writing
return results
# Editing an existing entry in the CSV
def edit(self, index, new_name, new_password):
rows = [] # Store all rows here
# Open CSV file for reading
with open('data.csv', mode='r') as file:
# Create a CSV reader
reader = csv.reader(file)
# Read all rows into the list
rows = list(reader)
# Iterate over each row
for row in rows:
# If index matches, update name and password
if row[0] == str(index):
row[2] = new_name
row[3] = new_password
# Open CSV file for writing
with open('data.csv', mode='w', newline='') as file:
# Create a CSV writer
writer = csv.writer(file)
# Write all rows back to the file
writer.writerows(rows)
file.close() # Close the file after writing
print("Credentials Edited Successfully.\n")
self.textBox("Credentials Edited Successfully.\n")
self.backup() # Create a backup of the CSV
# Deleting an entry from the CSV by index
def delete(self, index):
rows = [] # Store all rows here
# Open CSV file for reading
with open('data.csv', mode='r') as file:
# Create a CSV reader
reader = csv.reader(file)
# Read all rows into the list
rows = list(reader)
# Filter out the row to delete
rows = [row for row in rows if row[0] != str(index)]
# Open CSV file for writing
with open('data.csv', mode='w', newline='') as file:
# Create a CSV writer
writer = csv.writer(file)
# Write remaining rows back to the file
writer.writerows(rows)
file.close()# Close the file after writing
print("Credentials Deleted Successfully.\n")
self.textBox("Credentials Deleted Successfully.\n")
self.backup() # Create a backup of the CSV
# Creating a backup of the CSV file
def backup(self):
# Read all data from the CSV file
with open("data.csv", mode='r') as file:
data = file.read()
# Get the current working directory
dp = os.getcwd()
# Move to the parent directory
os.chdir("..")
# Create path for backup
cp = os.path.join(os.getcwd(), "MYPmanager_Backup", "data.csv")
if not os.path.isdir('MYPmanager_Backup'): # If 'BackupMYPmanager' not exists
os.makedirs('MYPmanager_Backup') # Create one, for back up
print("Creating MYPmanager_Backup")
# Write data to backup file
with open(cp, mode='w') as backup_file:
backup_file.write(data)
os.chdir(dp) # Restoring the default path
print("Credentials Backup Successfully.\n")
if __name__ == "__main__":
app = App()
app.mainloop()