-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddAccount.py
executable file
·62 lines (52 loc) · 2.7 KB
/
AddAccount.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
from Accounts import Accounts
from Encryption import Encryption
import values
from tkinter import *
from tkinter import messagebox
class AddAccount(Accounts):
def addAccount(self):
serviceName = self.service_name_entry.get()
accLogin = self.login_entry.get()
accPassword = self.password_entry.get()
if serviceName in self.servicesList:
Label(self.add_account_frame, text = "Such service exists, try again.", fg = "red").grid(row = 7, column = 0)
return
enc = Encryption(values.key1, values.key2)
encAccLogin = enc.encrypt(accLogin)
encAccPassword = enc.encrypt(accPassword)
newFile = open(values.data_path + serviceName + ".txt", 'w')
print(encAccLogin, file = newFile)
print(encAccPassword, file = newFile)
newFile.close()
servDataFile = open(values.data_path + "services.txt", 'a')
print(serviceName, file = servDataFile)
servDataFile.close()
messagebox.showinfo(message = "New account has beed added successfully.")
self.add_account_frame.pack_forget()
self.menu_frame.pack()
def back_to_menu(self):
self.add_account_frame.pack_forget()
self.menu_frame.pack()
def __init__(self, root, menu_frame):
super().__init__()
self.root = root
self.menu_frame = menu_frame
self.add_account_frame = Frame(root)
self.add_account_frame.pack()
if len(self.servicesList) == 30:
messagebox.showinfo(message = "You have achieved maximum number of 30 accounts. Please delete one first.")
self.back_to_menu()
return
self.service_name_entry = Entry(self.add_account_frame)
self.login_entry = Entry(self.add_account_frame)
self.password_entry = Entry(self.add_account_frame)
btn = Button(self.add_account_frame, text = "Add", command = self.addAccount, width = 10)
btnBack = Button(self.add_account_frame, text = "Back to menu", command = self.back_to_menu, width = 10)
Label(self.add_account_frame, text = "Insert service name", font = "Helvetica 20 bold").grid(row = 0, column = 0, pady = 20)
self.service_name_entry.grid(row = 1, column = 0)
Label(self.add_account_frame, text = "Insert your login", font = "Helvetica 18 bold").grid(row = 2, column = 0, pady = 20)
self.login_entry.grid(row = 3, column = 0)
Label(self.add_account_frame, text = "Insert your password", font = "Helvetica 18 bold").grid(row = 4, column = 0, pady = 20)
self.password_entry.grid(row = 5, column = 0)
btn.grid(row = 6, column = 0, pady = 20, sticky = 'e')
btnBack.grid(row = 6, column = 0, pady = 20, sticky = 'w')