Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2002-05-25
3
Medium Priority
?
6,221 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
BeyondWu earned 400 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Working from home is a dream for many people who aren’t happy about getting up early, going to the office, and spending long hours at work. There are lots of benefits of remote work for employees.
Let's take a look into the basics of ransomware—how it spreads, how it can hurt us, and why a disaster recovery plan is important.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

604 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