-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
executable file
·99 lines (87 loc) · 3.5 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
#!/usr/bin/env python3.5
import Database
import AESCipher
try:
import pyperclip
except ImportError:
print("pyperclip not found.")
pyperclip = None
def main():
while True:
print("(E)ncrypt, (D)ecrypt,\
(S)how all ids, (U)pdate id, De(l)ete id, E(x)it")
choice = input('> ')
Database.create_database()
if choice in ('e', 'E'):
website = input('Website: ')
username = input("Username: ")
search_res = Database.search_account(web=website, usr=username)
if search_res:
print("Can't encrypt. Account exists.")
else:
key = input("Key: ")
password = input("Password: ")
password = AESCipher.encrypt(key, password)
Database.create_account(
web=website, usr=username, pswd=password)
print('Done')
elif choice in ('d', 'D'):
website = input('Website: ')
username = input("Username: ")
search_res = Database.search_account(web=website, usr=username)
if search_res:
key = input("Key: ")
password = search_res['password']
try:
password = AESCipher.decrypt(key, password)
print("Password:", password)
if pyperclip:
pyperclip.copy(password)
print('Password saved to your clipboard.')
except Exception:
print('Incorrect Key. Try again.')
else:
print("Can't decrypt. Account doesn't exists.")
elif choice in ('u', 'U'):
website = input('Website: ')
username = input("Username: ")
search_res = Database.search_account(web=website, usr=username)
if search_res:
new_username = input("New Username: ")
new_password = input("New Password: ")
key = input("Key: ")
new_password = AESCipher.encrypt(key, new_password)
Database.update_account(
web=website, usr=username,
new_usr=new_username, new_pswd=new_password)
print("Done.")
else:
print("Can't update. Account doesn't exists.")
elif choice in ('l', 'L'):
website = input('Website: ')
username = input("Username: ")
search_res = Database.search_account(web=website, usr=username)
if search_res:
key = input("Key: ")
password = input("Enter password to delete account: ")
acc_pass = AESCipher.decrypt(key, search_res['password'])
if password == acc_pass:
Database.delete_account(web=website, usr=username)
print("Done")
else:
print("Can't delete account, unauthorized access.")
else:
print("Account doesn't exists.")
elif choice in ('s', 'S'):
search_res = Database.show_all()
print("{:^20} {:^20} {:^20} {:^20}".format(
"Website", "Username", "Last Used", "Create Date"))
print('~' * 100)
for data in search_res:
print("{:^20} {:^20} {:^20} {:^20}".format(*data))
print('~' * 100)
elif choice in ('x', 'X'):
break
else:
print('Invalid Choice.')
main()