TITLE Simple Login System
.MODEL SMALL
.STACK 64
.DATA
USERNAME DB 20 DUP('$')
PASSWORD DB 20 DUP('$')
INPUT_BUFFER DB 20 DUP('$')
PROMPT_USER DB 13,10,"Create a username: $"
PROMPT_PASS DB 13,10,"Create a password: $"
LOGIN_NAME DB 13,10,"Enter your username: $"
LOGIN_PASS DB 13,10,"Enter your password: $"
SUCCESS_MSG DB 13,10,"Login successful!$"
FAILURE_MSG DB 13,10,"Login failed. Please try again.$"
;------------------------------------------------------------------------------
.CODE
MAIN PROC FAR
MOV AX,@DATA
MOV DS,AX

; Signup: Prompt for username and password
MOV AH,09H
LEA DX,PROMPT_USER ; Display prompt for username
INT 21H

MOV AH,0AH
LEA DX,USERNAME  ; Store username directly into the buffer
INT 21H

MOV AH,09H
LEA DX,PROMPT_PASS ; Display prompt for password
INT 21H

MOV AH,0AH
LEA DX,PASSWORD  ; Store password directly into the buffer
INT 21H

; Prompt for login
MOV AH,09H
LEA DX,LOGIN_NAME ; Display prompt for login username
INT 21H

MOV AH,0AH
LEA DX,INPUT_BUFFER  ; Store login username directly into the buffer
INT 21H

; Prompt for password
MOV AH,09H
LEA DX,LOGIN_PASS ; Display prompt for login password
INT 21H

MOV AH,0AH
LEA DX,INPUT_BUFFER  ; Store login password directly into the buffer
INT 21H

; Compare the entered and saved username and password
MOV SI, OFFSET USERNAME
MOV DI, OFFSET INPUT_BUFFER
MOV CX, 20
REP CMPSB  ; Compare the STRINGS

JE LOGIN_FAILURE  ; Jump to failure message if not equal

MOV SI, OFFSET PASSWORD
MOV DI, OFFSET INPUT_BUFFER
MOV CX, 20
REP CMPSB  ; Compare the STRINGS

JE LOGIN_FAILURE  ; Jump to failure message if not equal

; Both username and password comparisons were successful
MOV AH, 09H
LEA DX, SUCCESS_MSG ; Display login success message
INT 21H

JMP EXIT_PROGRAM  ; Jump to exit the program

LOGIN_FAILURE:
MOV AH, 09H
LEA DX, FAILURE_MSG ; Display login fail message
INT 21H

JMP EXIT_PROGRAM  ; Jump to exit the program

EXIT_PROGRAM:
MOV AX,4C00H ; Exit
INT 21H

MAIN ENDP
END MAIN

I am new to this topic and recently I was required to create a login system where user type in their name and password then the value is stored.After that, the user need to type in the name and password they type in as their login information and the value will be compared to validate either success or fail.I tested many different code but the result doesnt seems to be what I needed.Any suggestion?

What result are you getting versus what you’re expecting?

commented: The compare and loop was not working as it intended probably cause it was my first time coding assembly so i couldnt know where the exact problem. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.