-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpasswordmanager.asm
More file actions
318 lines (260 loc) · 5.25 KB
/
passwordmanager.asm
File metadata and controls
318 lines (260 loc) · 5.25 KB
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
.MODEL SMALL
.STACK 100H
.DATA
; -----------------------
; Messages
; -----------------------
welcome_msg DB 0Dh,0Ah,'--- PASSWORD MANAGER ---',0Dh,0Ah,'$'
ask_master DB 0Dh,0Ah,'Enter Master Password: $'
wrong_pass DB 0Dh,0Ah,'Wrong Password! Exiting...$'
login_ok DB 0Dh,0Ah,'Login Successful!$'
menu_msg DB 0Dh,0Ah,'1. Add Account',0Dh,0Ah
DB '2. View Accounts',0Dh,0Ah
DB '3. Delete All',0Dh,0Ah
DB '4. Exit',0Dh,0Ah
DB 'Enter choice: $'
ask_user DB 0Dh,0Ah,'Enter Username: $'
ask_pass DB 0Dh,0Ah,'Enter Password: $'
acc_added DB 0Dh,0Ah,'Account added.$'
no_acc_msg DB 0Dh,0Ah,'No accounts found.$'
all_del DB 0Dh,0Ah,'All accounts deleted.$'
colon_sp DB ': $'
; -----------------------
; Data storage
; -----------------------
master_pass DB 'admin',0
MAX_ACC EQU 5
MAX_LEN EQU 20
usernames DB MAX_ACC*MAX_LEN DUP('$')
passwords DB MAX_ACC*MAX_LEN DUP('$')
plain_pw DB MAX_LEN DUP('$') ; buffer for decrypted password
account_cnt DB 0
choice DB ?
; input buffer (for int 21h AH=0Ah)
inbuf DB 21,0,21 DUP('$')
; -----------------------
; Code
; -----------------------
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
; Welcome + login
MOV DX,OFFSET welcome_msg
MOV AH,09h
INT 21h
CALL LOGIN
CMP AL,0
JE EXIT_PROG
MAIN_LOOP:
MOV DX,OFFSET menu_msg
MOV AH,09h
INT 21h
; read choice (1 char)
MOV AH,01h
INT 21h
MOV choice,AL
CMP AL,'1'
JE DO_ADD
CMP AL,'2'
JE DO_VIEW
CMP AL,'3'
JE DO_DELETE
CMP AL,'4'
JE EXIT_PROG
JMP MAIN_LOOP
DO_ADD:
CALL ADD_ACCOUNT
JMP MAIN_LOOP
DO_VIEW:
CALL VIEW_ACCOUNTS
JMP MAIN_LOOP
DO_DELETE:
CALL DELETE_ALL
JMP MAIN_LOOP
EXIT_PROG:
MOV AX,4C00h
INT 21h
MAIN ENDP
; -----------------------
; Procedures
; -----------------------
; -------- LOGIN --------
LOGIN PROC
MOV DX,OFFSET ask_master
MOV AH,09h
INT 21h
CALL READ_STRING
; compare length first
MOV CL,[inbuf+1] ; typed length
CMP CL,5 ; "admin" length = 5
JNE bad_pass
; compare characters
LEA SI,inbuf+2 ; typed chars
LEA DI,master_pass ; "admin"
check_loop:
LODSB
CMP AL,[DI]
JNE bad_pass
INC DI
DEC CL
JNZ check_loop
; all matched
MOV DX,OFFSET login_ok
MOV AH,09h
INT 21h
MOV AL,1
RET
bad_pass:
MOV DX,OFFSET wrong_pass
MOV AH,09h
INT 21h
MOV AL,0
RET
LOGIN ENDP
; -------- ADD_ACCOUNT --------
ADD_ACCOUNT PROC
CMP account_cnt,MAX_ACC
JAE add_full
; username
MOV DX,OFFSET ask_user
MOV AH,09h
INT 21h
CALL READ_STRING
LEA SI,inbuf+2
MOV CL,[inbuf+1]
MOV DI,OFFSET usernames
CALL GET_REC_PTR
CALL COPY_TO_RECORD
; password
MOV DX,OFFSET ask_pass
MOV AH,09h
INT 21h
CALL READ_STRING
LEA SI,inbuf+2
MOV CL,[inbuf+1]
MOV DI,OFFSET passwords
CALL GET_REC_PTR
CALL ENCRYPT_TO_RECORD
INC account_cnt
MOV DX,OFFSET acc_added
MOV AH,09h
INT 21h
RET
add_full:
MOV DX,OFFSET no_acc_msg
MOV AH,09h
INT 21h
RET
ADD_ACCOUNT ENDP
; -------- VIEW_ACCOUNTS --------
VIEW_ACCOUNTS PROC
CMP account_cnt,0
JE va_none
XOR BX,BX ; index=0
va_next:
CMP BL,account_cnt
JAE va_done
; print username
MOV DX,OFFSET usernames
CALL GET_REC_PTR
MOV DX,DI
MOV AH,09h
INT 21h
; print ": "
MOV DX,OFFSET colon_sp
MOV AH,09h
INT 21h
; decrypt password
MOV DX,OFFSET passwords
CALL GET_REC_PTR
MOV SI,DI
LEA DI,plain_pw
CALL DECRYPT_FROM_RECORD
MOV DX,OFFSET plain_pw
MOV AH,09h
INT 21h
; newline
MOV DL,0Dh
MOV AH,02h
INT 21h
MOV DL,0Ah
INT 21h
INC BL
JMP va_next
va_done:
RET
va_none:
MOV DX,OFFSET no_acc_msg
MOV AH,09h
INT 21h
RET
VIEW_ACCOUNTS ENDP
; -------- DELETE_ALL --------
DELETE_ALL PROC
MOV account_cnt,0
MOV DX,OFFSET all_del
MOV AH,09h
INT 21h
RET
DELETE_ALL ENDP
; -------- Utilities --------
; READ_STRING -> reads into inbuf
READ_STRING PROC
MOV DX,OFFSET inbuf
MOV AH,0Ah
INT 21h
RET
READ_STRING ENDP
; get record pointer (DI = base, BX=index)
GET_REC_PTR PROC
MOV AX,BX
MOV CL,MAX_LEN
MUL CL
ADD DI,AX
RET
GET_REC_PTR ENDP
; copy CL bytes from SI->DI, add '$'
COPY_TO_RECORD PROC
cpr_loop:
CMP CL,0
JE cpr_end
LODSB
STOSB
DEC CL
JMP cpr_loop
cpr_end:
MOV AL,'$'
STOSB
RET
COPY_TO_RECORD ENDP
; encrypt copy with +3
ENCRYPT_TO_RECORD PROC
etr_loop:
CMP CL,0
JE etr_end
LODSB
ADD AL,3
STOSB
DEC CL
JMP etr_loop
etr_end:
MOV AL,'$'
STOSB
RET
ENCRYPT_TO_RECORD ENDP
; decrypt from SI -> DI until '$'
DECRYPT_FROM_RECORD PROC
dfr_loop:
LODSB
CMP AL,'$'
JE dfr_done
SUB AL,3
STOSB
JMP dfr_loop
dfr_done:
MOV AL,'$'
STOSB
RET
DECRYPT_FROM_RECORD ENDP
END MAIN