.MODEL SMALL
.STACK 100H
.DATA
MSG DB 'Enter password: $'
DISPLAY_MSG DB 0dh, 0ah, 'NAME: display name', 0dh, 0ah, 'ID NUMBER: display number', '$'
ERROR_MSG DB 'Password does not match.!$'
PASSWORD DB '123'
BUFFER DB 4
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA DX, MSG
MOV AH, 9
INT 21H ; print prompt message
MOV AH, 0AH
LEA DX, BUFFER
INT 21H ; read input from user
MOV SI, OFFSET BUFFER+2 ; skip first byte (input length)
MOV DI, OFFSET PASSWORD
MOV CX, 3 ; compare up to 6 characters
CMP_LOOP:
LODSB ; load byte from SI into AL, increment SI
CMP AL, [DI] ; compare with password character
JNE CMP_FAIL ; jump to failure if not equal
INC DI ; move to next password character
LOOP CMP_LOOP ; repeat until CX is zero
JMP SUCCESS
CMP_FAIL:
; passwords don't match, print error message
LEA DX, ERROR_MSG
MOV AH, 9
INT 21H
SUCCESS:
; passwords match, print success message
LEA DX, DISPLAY_MSG
MOV AH, 9
INT 21H
MOV AH, 4CH
INT 21H ; return to DOS
MAIN ENDP
END MAIN
How do I change this so that the user input is not displayed. I tried using int 21h ah=08h
, but I can't seem to make it work.
I tried using int 16h ah=00h
, and also tried creating a loop using int 21h ah=08h
. It works but the user input is not stored within the declared password db
.
Declaration od BUFFER DB 4
is not sufficient, see BUFFERED INPUT, it should be something like
BUFFER DB 4,0,'XXXX'
. However, if you don't want to reveal the entered characters, use DOS function CHARACTER INPUT WITHOUT ECHO. In this case you don't have to store input data to memory, and just compare each obtained character with the PASSWORD template.
Instead of
MOV AH, 0AH
MOV DX, BUFFER
INT 21H ; read input from user
try this:
LEA SI,[PASSWORD]
MOV CX,3 ; Size of the PASSWORD.
MOV AH,8 ; Input one character to AL without echo.
CMP_LOOP:
INT 21H ; Get one character from keyboard.
CMP AL,[SI] ; Does it match the template?
JNE CMP_FAIL
INC SI ; Compare the next character.
LOOP CMP_LOOP:
SUCCESS: ; passwords match, print success message
MOV DX, DISPLAY_MSG
MOV AH, 9
INT 21H
MOV AX, 4C00H ; Terminate with errorlevel 0.
INT 21H ; return to DOS
CMP_FAIL: ; passwords don't match, print error message
MOV DX, ERROR_MSG
MOV AH, 9
INT 21H
MOV AX, 4C08H ; Terminate with errorlevel 8.
INT 21H ; return to DOS