This repository has been archived by the owner on Nov 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCodesEditor.py
117 lines (99 loc) · 2.8 KB
/
CodesEditor.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
import getpass
import time
import sys
import shutil
#Custom Libs
import pyotp
import crypt
import FileWork as fw
### My fucntions here starts
def getTime():
time_last = int(time.strftime("%S"))
if time_last>=30:
time_last = time_last - 30
time_last = 30 - time_last
return ("(You have %s seconds left) " % str(time_last))
def help():
teer()
print("1 - add\n2 - del\n3 - change\n4 - get\n\n9 - exit")
teer()
def add(pswd):
'''
Add codes to codes.enc
'''
name = input("Enter name of new service: ")
secure_code = input("Secure code: ")
codes = fw.OpenJson("codes", pswd)
codes[name] = secure_code
fw.SaveJson("codes", codes, pswd)
totp = pyotp.TOTP(secure_code)
print("Current code:", totp.now())
def delete(codes, pswd):
teer()
print("WARNING!\nTHIS ACTION MAY DELETE YOUR SECURE DATA\nPLEASE BE CAREFUL")
teer()
time.sleep(1)
print("Enter name service that you want to delete:\n")
service_name = input()
if service_name not in codes:
print("This key is not in the codes.enc")
else:
print("Are you sure want to delete %s ?" % service_name.upper() )
ans = input()
if ans == "yes" or ans == "y":
shutil.copy2(r'codes.enc', r'codes.enc.OLD')
del codes[service_name]
fw.SaveJson("codes", codes, pswd)
teer()
print("Succeful delete!")
teer()
def change(codes):
pswd_new = getpass.getpass("Enter new password: ")
pswd_new_second = getpass.getpass("Repeat your new password: ")
if pswd_new != pswd_new_second:
print("Passwords do not match")
else:
fw.SaveJson("codes", codes, pswd_new)
print("Succeful password change")
teer()
def get(codes):
service_name = input("Enter name of service: ")
if service_name in codes:
secure_code = codes[service_name]
totp = pyotp.TOTP(secure_code)
print( getTime() )
print(service_name + ": " + totp.now())
teer()
def getValues(pswd):
teer()
print("Youre services:\n")
codes = fw.OpenJson("codes", pswd)
for code in codes:
print(code)
teer()
return codes
def teer():
s = "\n--------------------"
print(s + "\n")
### My functions here ends(?)
teer()
pswd = getpass.getpass("Enter password: ")
help()
codes = getValues(pswd)
while True:
print("Enter command:\n")
cmd = input()
if cmd == "add" or cmd == "1":
add(pswd)
getValues(pswd)
if cmd == "del" or cmd == "2":
delete(codes, pswd)
getValues(pswd)
if cmd == "change" or cmd == "3":
change(codes)
sys.exit()
if cmd == "get" or cmd == "4":
get(codes)
if cmd == "exit" or cmd == "ex" or cmd == "9":
print("~~~~~~ GoodBye ~~~~~~")
sys.exit()