Solved

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

Posted on 2002-05-25
3
5,016 Views
Last Modified: 2008-03-10
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.

0
Comment
Question by:ImraneA
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
BeyondWu earned 100 total points
ID: 7036366
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
 
LVL 9

Expert Comment

by:BeyondWu
ID: 7036372
Sorry,the line:
 call IsCharAlphaNumeric        ;check the first character of the password.
should be:
call IsCharAlphaNumeric        ;check the other character of the password.
0
 

Author Comment

by:ImraneA
ID: 7043725
Sorry for delay, excellent answer.

Thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now