-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
198 lines (169 loc) · 4.43 KB
/
ui.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
import curses
import pswdDB
stdscr = curses.initscr() #intiate window
def start(stdscr):
curses.noecho()
curses.cbreak()
stdscr.keypad(True)
selection = 0 #first menu
while True:
stdscr.clear()
if selection == 1:
stdscr.addstr(0, 0, "Create a new DB:")
stdscr.addstr(1, 0, "Load an old DB:", curses.A_REVERSE)
else:
stdscr.addstr(0, 0, "Create a new DB:", curses.A_REVERSE)
stdscr.addstr(1, 0, "Load an old DB:")
c = stdscr.getch()
if c == curses.KEY_UP or c == curses.KEY_DOWN:
selection += 1
selection %= 2
elif c == ord('q') or c == curses.KEY_LEFT:
break # Exit the while loop
elif c == curses.KEY_RIGHT or c == curses.KEY_ENTER: #enter next menulevel
if selection == 0:
newDB(stdscr)
else:
oldDB(stdscr)
curses.nocbreak()
stdscr.keypad(False)
curses.echo()
curses.endwin()
def newDB(stdscr):
curses.echo()
stdscr.keypad(False)
stdscr.clear() #get path to DB
stdscr.addstr(0, 0, "Enter path to new DB:")
stdscr.move(1, 0)
stdscr.refresh()
path = stdscr.getstr(1,0).decode()
curses.noecho()
while True: #get mpswd and reassure
stdscr.clear() #get mpswd
stdscr.addstr(0, 0, "Enter new master password")
stdscr.move(1, 0)
stdscr.refresh
mpswd = stdscr.getstr(1,0).decode()
stdscr.clear() #get mpswd again
stdscr.addstr(0, 0, "Repeat new master password")
stdscr.move(1, 0)
stdscr.refresh
rmpswd = stdscr.getstr(1,0).decode()
if mpswd == rmpswd: #create and save DB
x = pswdDB.pswdDB(mpswd)
pswdDB.saveDB(path, x)
break
else:
stdscr.clear()
stdscr.addstr(0, 0, "Didn't match\tHit any key")
stdscr.refresh()
stdscr.getch()
stdscr.keypad(True)
def oldDB(stdscr):
curses.echo()
stdscr.keypad(False)
stdscr.clear() #get path to DB
stdscr.addstr(0, 0, "Enter path to DB:")
stdscr.move(1, 0)
stdscr.refresh()
path = stdscr.getstr(1,0).decode()
DB = pswdDB.loadDB(path)
curses.noecho()
stdscr.keypad(True)
selection = 0 #first menu
while True:
stdscr.clear()
if selection == 1:
stdscr.addstr(0, 0, "Save password:")
stdscr.addstr(1, 0, "Load password:", curses.A_REVERSE)
else:
stdscr.addstr(0, 0, "Save password:", curses.A_REVERSE)
stdscr.addstr(1, 0, "Load password:")
c = stdscr.getch()
if c == curses.KEY_UP or c == curses.KEY_DOWN:
selection += 1
selection %= 2
elif c == ord('q') or c == curses.KEY_LEFT:
break # Exit the while loop
elif c == curses.KEY_RIGHT or c == curses.KEY_ENTER: #enter next menulevel
if selection == 0:
newDB(stdscr, DB)
else:
oldDB(stdscr, DB)
def oldPswd(stdscr, DB):
curses.echo()
stdscr.keypad(False)
stdscr.clear()
stdscr.addstr(0, 0, "Enter site name:")
stdscr.move(1, 0)
stdscr.refresh()
site = stdscr.getstr(1,0).decode()
curses.noecho()
while True:
stdscr.clear()
stdscr.addstr(0, 0, "Enter master password:")
stdscr.move(1, 0)
stdscr.refresh()
mpswd = stdscr.getstr(1,0).decode()
try:
login, pswd = pswdDB.getpswd(DB, site, mpswd)
break
except PasswordError:
stdscr.clear()
stdscr.addstr(0, 0, "Didn't match\tHit any key")
stdscr.getch()
stdscr.clear()
stdscr.addstr(0, 0, "Login: " + login)
stdscr.addstr(1, 0, "Password: " + pswd)
stdscr.addstr(2, 0, "Hit any key")
stdscr.getch()
curses.echo()
stdscr.keypad(True)
def newPswd(stdscr, DB):
curses.echo()
stdscr.keypad(False)
stdscr.clear()
stdscr.addstr(0, 0, "Enter site name:")
stdscr.move(1, 0)
stdscr.refresh()
site = stdscr.getstr(1,0).decode()
stdscr.clear()
stdscr.addstr(0, 0, "Enter login:")
stdscr.move(1, 0)
stdscr.refresh()
login = stdscr.getstr(1,0).decode()
curses.noecho()
while True: #get mpswd and reassure
stdscr.clear() #get mpswd
stdscr.addstr(0, 0, "Enter password")
stdscr.move(1, 0)
stdscr.refresh
pswd = stdscr.getstr(1,0).decode()
stdscr.clear() #get mpswd again
stdscr.addstr(0, 0, "Repeat password")
stdscr.move(1, 0)
stdscr.refresh
rpswd = stdscr.getstr(1,0).decode()
if pswd == rpswd: #create and save DB
break
else:
stdscr.clear()
stdscr.addstr(0, 0, "Didn't match\tHit any key")
stdscr.refresh()
stdscr.getch()
while True:
stdscr.clear()
stdscr.addstr(0, 0, "Enter master password:")
stdscr.move(1, 0)
stdscr.refresh()
mpswd = stdscr.getstr(1,0).decode()
try:
pswdDB.addpswd(DB, site, login, pswd, mpswd)
break
except PasswordError:
stdscr.clear()
stdscr.addstr(0, 0, "Didn't match\tHit any key")
stdscr.getch()
curses.echo()
stdscr.keypad(True)
start(stdscr)