Assembly Language Program - "Prompts a user to enter password"

Hi there

I am Newie to this area, any help greatly appreciated.

Problem:-

Write a program which prompts the user to enter a password.  The password needs to be read in and stored in memory.

Valid Password -

1.> 6 and 12 <= chars
2.1st char be letter
3.rest aplha

A.Invalid char error message appears
B.Password entered, length check done.  Error message appears otherwise.

Questions:-

1.Any suggestions on how to write this program in assembly .

Thanks.

ImraneAAsked:
Who is Participating?
 
BeyondWuConnect With a Mentor Commented:
ImraneA:
I think it depend on the which assembler you are using
and which type of app(gui/console) you are developing.

The following code for console type app.
You can build it under MASM32.
.386
.model flat,stdcall
option casemap:none

include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
include \masm32\include\windows.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

.data
cr      equ 0dh
lf      equ 0ah
byteswrote      dd 0
hstdo           dd 0
hstdi           dd 0
ok_txt           db 'Password is OK!',0
Info_txt        db 'Please Input your password:',0
error_txt       db 'The length of password should in this scope(6~12 chars)!',cr,lf,0
error2_txt      db 'The first character should be a letter!',cr,lf,0
error3_txt      db 'The other character should be a letter or numeric!',cr,lf,0
password        db  16 dup(0)  ;include cr,lf,0

.code
start:
        call    GetSHandle
        lea     ebx,Info_txt
        call    WriteString
        call    GetPassword
        push    0
        call    ExitProcess

GetSHandle proc
        push    STD_OUTPUT_HANDLE
        call    GetStdHandle
        mov     [hstdo],eax            
        push    STD_INPUT_HANDLE
        call    GetStdHandle
        mov     [hstdi],eax
        ret
GetSHandle endp

WriteString proc
        pushad
        mov     edi,ebx
        xor     eax,eax
        mov     ecx,0fffh
        cld
sc_loop:        
        scasb                                ; find end of string
        jz      fnd
        loop sc_loop
fnd:    
        mov     ecx,edi              
        sub     ecx,ebx
        push    0
        push    offset byteswrote
        push    ecx    
        push    ebx
        push    [hstdo]
        call    WriteConsole
        popad
        ret
WriteString endp

GetPassword proc      
        pushad
        lea edi, password
        xor eax,eax
        stosb
        dec edi
        push 0                      ;lpReserved
        push offset byteswrote      ;lpNumberofCharsRead
        push 15                     ;nNumberOfCharsToRead
        push edi                    ;lpBuffer
        push [hstdi]                ;hConsoleInput
        call ReadConsoleA
        popad

        sub [byteswrote],2
               
        cmp [byteswrote], 12        ;if the length of password > 12
        JG  error
        cmp [byteswrote], 6         ;if the length of password < 6
        JB  error

        lea edi, password
        movsx edx,byte ptr [edi]
        push edx
        call IsCharAlpha             ;check the first character of the password.
        cmp eax, TRUE
        JNE error2

loopx:  
        add edi,1                               ;check the other characters
        movsx edx,byte ptr [edi]
        test edx, edx
        je finished
        cmp edx, cr                  ;omit cr and lf.
        je finished
        cmp edx, lf
        je finished
           
        push edx
        call IsCharAlphaNumeric        ;check the first character of the password.
        cmp eax, TRUE
        JNE error3
        ; here other code to check if the password is a valid password.
        jmp loopx
       
finished:
        lea     ebx,ok_txt
        jmp  return
        ret
error:
        lea     ebx,error_txt
        jmp  return
error2:
        lea     ebx,error2_txt
        jmp  return
error3:
        lea     ebx,error3_txt
return:
        call    WriteString
        ret
             
GetPassword endp

end start

0
 
BeyondWuCommented:
Sorry,the line:
 call IsCharAlphaNumeric        ;check the first character of the password.
should be:
call IsCharAlphaNumeric        ;check the other character of the password.
0
 
ImraneAAuthor Commented:
Sorry for delay, excellent answer.

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.