flat assembler
Message board for the users of flat assembler.

Index > DOS > How to read and verify a password?

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Hi!!
I need to write a program that gets the input from keyboard and compares with 'pass', if it is equal than display 'Welcome!', else display 'Wrong password' and returns to the main question.
I tried this, but isn't working:

Code:
org 100h
use16
jmp _ini
_msg db 'Enter password:',10,13,'$'
_ok db 'Welcome!',10,13,'$'
_no db 'Wrong password!',10,13,'$'
_p db 4
_ini:
mov dx,_msg
mov ah,9
int 21h
mov dx,_p
mov ah,0Ah
int 21h
cmp al,'pass'
je ok
mov dx,_no
mov ah,9
int 21h
jmp _ini
ok:
mov dx,_ok
mov ah,9
int 21h
_end:
mov ah,4Ch
int 21h
    



Thanks for the helps!!!
Post 25 Sep 2003, 20:26
View user's profile Send private message Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Please help me!!! I need an example....
Post 25 Sep 2003, 22:05
View user's profile Send private message Reply with quote
Yawgmoth



Joined: 20 Aug 2003
Posts: 37
Yawgmoth
Try putting your data at the end of the program.
Post 25 Sep 2003, 22:06
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
No, he is correctly jumping over the data.
The problem is that you are comparing one byte in AL to a multi-byte value. The text "pass" consists of four bytes (characters), so you have to read four character from keyboard consecutively and compare that sequence to sequence of bytes that makes the password.
Post 25 Sep 2003, 22:14
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
Could you give me an example please??
Thanks Privalov!!!
Post 25 Sep 2003, 22:34
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
Just make it with one character first (for example modify your above program with "p" instead of "pass") and then try to repeat the same scheme for more characters (in a loop preferably).
Post 25 Sep 2003, 22:43
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
But, if I don't know how many letters will go, example:
What's your name?
user enters--> John
Hi John!!
How could I do this?
Post 25 Sep 2003, 22:49
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
Oh, one more thing - you have not reserved the space for your buffer correctly, it should be:
Code:
_p db 4,0
   rb 4    

And to get the first character of read string into AL (as you are then trying to check the contents of AL), you should do:
Code:
mov al,[_p+2]    

as the first byte is the maximum size of buffer and the second byte is the count of read characters, and then the characters follow, so they begin from _p+2 address.
Post 25 Sep 2003, 22:51
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
OK, here you are with example:
Code:
        org     100h


        mov     dx,_msg
        mov     ah,9
        int     21h

        mov     dx,_buffer
        mov     ah,0Ah
        int     21h

        mov     dx,_greet1
        mov     ah,9
        int     21h
        mov     cl,[_buffer+1]
        xor     ch,ch
        mov     bx,_buffer+2
  _loop:
        mov     ah,2
        mov     dl,[bx]
        int     21h
        inc     bx
        loop    _loop
        mov     dx,_greet2
        mov     ah,9
        int     21h

        xor     ah,ah
        int     16h

        int     20h

_msg db 'Enter your name: ',24h
_greet1 db 13,10,'Hello, ',24h
_greet2 db '!!!',13,10,24h
_buffer db 80h,0
        rb 80h    
Post 25 Sep 2003, 22:56
View user's profile Send private message Visit poster's website Reply with quote
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY
That was what I was looking for, thanks!!!
Post 25 Sep 2003, 22:58
View user's profile Send private message Reply with quote
WhiteDwarf



Joined: 25 Dec 2003
Posts: 17
WhiteDwarf
Quote:
_loop:
mov ah,2


Would the code be optimized if you put that line of code before the loop. So then the loop won't needlessly be loading ah with 2 every time.?
Post 15 Jan 2004, 06:15
View user's profile Send private message Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio
cmp al,'pass'
is an invalid instruction ,fasm must output a error size comment
Post 15 Jan 2004, 09:06
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Privalov wrote:
OK, here you are with example:


Smile nice,
the dos function to read a string, i have discovered the new line bug in this code 5 years ago, so i have recognized it.
but this can be a size optimization method under dos. Smile
Post 27 Oct 2004, 10:35
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.