Solved

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

Posted on 2002-05-25
3
5,311 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

776 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