How can I use asterisk to mask the password?

Viewed 456

I try to write a simple program to let user enter password with _GetCh function to get keyboard input, after then using compare function when user input a to z will masked as *, but it doesn't work Can anyone help me which part am I wrong?

here is my code, thanks

.model small
.586
.stack 100h
INCLUDE PCMAC.INC
.DATA

MSG DB 'Enter Password: $'
PWD DB 'abcd'

.CODE

PASSWORD PROC
     mov ax, @DATA
     mov ds, ax
     mov dx, offset pwd

GetLoop:
     _Begin
     _PutStr msg
     _GetCh noEcho
     cmp al, 13
     je DONE
     cmp al, 'a'
     jnae al, EchoIt
     cmp al, 'z'
     jnbe al, EchoIt
     add al, '*'

EchoIt:
     _PutCh al
     jmp GetLoop

DONE:
     _Exit 0

PASWORD ENDP
END PASSWORD
1 Answers
jnae al, EchoIt
jnbe al, EchoIt

What assembler are you using that allows this peculiar syntax? Also, try to use the simpler form of an instruction. jnae is the same as jb which is much more readable.

To replace the characters from 'a' to 'z' by an asterisk, you can use the following:

     ; here you would insert AL in buffer
     ; and increment the counter
     cmp al, 'a'
     jb  EchoIt
     cmp al, 'z'
     ja  EchoIt
     mov al, '*'
EchoIt:
     _PutCh al

For your task you will have to keep the originally inputted characters in a buffer. How else could you hope to verify the password? You must make the insertion before doing this asterisk-replacement.


You don't want to display the message for each character of the password! Put your GetLoop label elsewhere:

     _Begin
     _PutStr msg
GetLoop:
     _GetCh noEcho
     cmp al, 13
     je  DONE
     cmp al, 8
     jne Character
Backspace:

     ...

Character:
     ; buffer and counter++
     cmp al, 'a'
     jb  EchoIt
     cmp al, 'z'
     ja  EchoIt
     mov al, '*'
EchoIt:
     _PutCh al
     jmp GetLoop
DONE:
Related