For the login part is good, everything works well on that part. But for registering a new account part, it keeps showing the invalid message although I full all the requirements which are username cant be repeated and the length of username should be more than 5 letters.
Here is my code
.MODEL SMALL
.STACK 64
.DATA
welMsg DB "Welcome to Shopping Mall Company! ^_^"
DB 13,10,"This is our company Loyalty Program System."
DB 13,10,"Please login or register your account before proceeding to the next step.","$"
; indexing for usernames and passwords
usersIndex dw usr1,usr2,usr3,usr4,usr5,usr6
usr1 DB "siti02$"
usr2 DB "joey02$"
usr3 DB "robert$"
usr4 DB 31 dup(?)
usr5 DB 31 dup(?)
usr6 DB 31 dup(?)
userspasswordIndex dw usrpsw1,usrpsw2,usrpsw3,usrpsw4,usrpsw5,usrpsw6
usrpsw1 DB "siti123456",'$'
usrpsw2 DB "joey123456",'$'
usrpsw3 DB "robert123",'$'
usrpsw4 DB 31 dup(?)
usrpsw5 DB 31 dup(?)
usrpsw6 DB 31 dup(?)
;****************************** loginmessage for User Available or Not***********************
loginmessage0 DB "************* Main Menu *************$"
loginmessage1 DB "Enter 1 to Register a New Account$"
loginmessage2 DB "Enter 2 to Login Account$"
loginmessage4 DB "Choice: $"
loginmessage5 DB "Invalid Choice, please select only 1 to 3 option$"
loginmessageline DB "*************************************$"
;***********exitloginmessage*********
exitloginmessage DB "Enter 3 for Exit$"
;****************************login loginmessage****************************
totalUsr dw 3 ; store total available registered users
IMSG DB "ACCESS DENIED$"
VMSG DB "ACCESS GRANTED!$"
; ******************************loginmessage for User login*************************
loginmessage6 DB "*******Login*********$"
loginmessage7 DB "Enter username: $"
loginmessage8 DB "Enter password: $"
; ***********************for register new account**********************************
loginmessage9 DB "Set your user account(username): $"
loginmessage10 DB "Set your password: $"
;***********************end message****************************
endMsg DB 13,10,"Thanks for using Loyalty Program System.See you again! =)"
DB 13,10," _ _ _ _ __ __ __ ___ __ __ __"
DB 13,10,"|_ _ _ _| | | | | / __ \ | \ \ | | | | / / "
DB 13,10," | | | |_| | | |__| | | \ \| | | |_/ / "
DB 13,10," | | | _ | | __ | | |\ \ | | _ \ "
DB 13,10," |_| |__| |__| |_| |_| |__| \___| |__| \___\ ","$"
;***********************input acc& pssw variable****************************
regUser DB 31 dup(?)
regPssw DB 31 dup(?)
;*****************************message for creating fail account**********************
repeatAccMsg DB "Sorry the account has been used, Try other$"
invalidLengthForUsername DB "Invalid username, Username Length must be greater than 5 characters$"
invalidPassError DB "Sorry your password dose not fulfil, Password Length must be greater than 8 characters$"
;**************************login sucess & fail message*******************************
invalidAccountInfo DB "Invalid Account Info, Username and password is not matched with database$"
successfullLoginMsg DB "Your Account is Successfully login$"
;*************** message after register********************************
confirmAccountMsg0 DB "By register this account,I agree to the terms and conditions$"
confirmAccountMsg DB "Confirm to create the account(y/n): $"
accountCreatedMsg DB "Account created!!!!$"
accountFailCreatedMsg DB "Account create fail!$"
databaseFullMsg DB "Sorry, database is Full, We can't create your account$"
.CODE
NEWLINE MACRO
;newline
MOV AH,02H
MOV DL,0DH
INT 21H
MOV DL,0AH
INT 21H
ENDM
CLEARSCREEN MACRO
MOV AX, 0600H
MOV BH,71H
MOV CX, 0000H
MOV DX,174FH
INT 10H
ENDM
PRINTSTRING MACRO INPUT
MOV AH, 09H
LEA DX, INPUT
INT 21H
ENDM
INPUTOPTION MACRO
MOV AH, 01H
INT 21H
ENDM
STORING MACRO INPUT
mov ah, 3Fh ; read an array of bytes from keyboard-0
mov bx, 0 ; bx = 0 (select keyboard)
mov cx, 30 ; cx = 30 (maximum bytes to read)
lea dx, INPUT ; stored in DS:DX
int 21h
ENDM
isValidAccountDetails proc
lea si, usersIndex ; point to list of customername
lea di, userspasswordIndex ; point to list of passwords
mov cx, totalUsr
checkUserAccount:
push si ; push pointer of Username on stack
push di ; push pointer of password on stack
mov dx, [si] ; read one password from
mov si, dx ; store address in si
lea di, regUser ; store address of regUser in di
checkNextChar:
mov al, [si] ; read character of stored Username string
mov bl, [di] ; read character of new Username string
cmp al,bl ; compare chars, if not same
JNE notMatch
cmp al, '$' ; if same last character
JE verifyPassword ; now verifyPassword
inc si
inc di
JMP checkNextChar
verifyPassword:
pop si
pop di
mov dx, [si]
mov si, dx ; di will contain actual correct password
mov di, offset regPssw ; si will contain Agent typed password
checkPsw:
mov al,[si] ; read char from original psw string
mov bl,[di] ; read char from new psw string
cmp al,bl ; if chars are not same, then account information is invalid
JNE wrongData
cmp al,'$' ; if we reach last character '$'
JE correctData ; then Agent account data is correct
inc si
inc di
JMP checkPsw
notMatch:
pop di
pop si
add si, 2
add di, 2
loop checkUserAccount
wrongData:
mov ax, 0 ; store ax = 0 when wrong / invalid account information
ret
correctData:
mov ax, 1 ; store ax = 1 when correct / valid account information
ret
isValidAccountDetails endp
; this proc will check if the username is already registered or not
; if the username is already in used, then it will return ax = 0, otherwise ax = 1
isValidUserName proc
mov cx, 0
mov si, offset usersIndex
checkUserExist:
push si
cmp cx, totalUsr
JE validUserName
mov dx, [si]
mov si, dx
mov di, offset regUser
call isSameStrings
cmp ax, 1
JE invalidUserName
pop si
add si, 2
inc cx
JMP checkUserExist
validUserName:
pop si
mov ax, 1
ret
invalidUserName:
pop si
mov ax, 0
ret
isValidUserName endp
; this proc will check if two strings are same or not,
; string 1 is si, string 2 is di
isSameStrings proc
; si old string
; di new string
checkSame:
mov al,[si]
mov bl,[di]
cmp al,bl
JNE notSame
inc si
inc di
cmp al,'$'
JNE checkSame
mov ax, 1
ret
notSame:
mov ax, 0
ret
isSameStrings endp
createAccount proc
; get location of username for new available account
lea si, usersIndex
mov ax, totalUsr
mov bl, 2 ;user address totalUsr * 2 give me actual address for new usr
mul bl
add si, ax ; si will point to required address for username
mov dx, [si]
mov si, dx ; point to location of username
lea di, regUser
storeUser:
mov al,[di]
mov [si], al
cmp al,'$'
JE storePassword
inc si
inc di
JMP storeUser
storePassword: ; get location of password for new available account
lea si, userspasswordindex
mov ax, totalUsr
mov bl, 2
mul bl ;user address totalUsr * 2 give me actual address for new usr
add si, ax ; si will point to required address for password
mov dx, [si]
mov si, dx ; point to location of password
lea di, regPssw
storePsw: ; save password
mov al,[di]
mov [si], al
cmp al,'$'
JE accountCreated
inc si
inc di
JMP storePsw
accountCreated:
add totalUsr,1 ; update total users
ret
createAccount endp
; this proc store '$' symbol at the end of username string
placeEndSymbolForUser proc
; for username
mov si, offset regUser
readNextChar1:
mov al,[si]
cmp al,0DH
JE storeEndSymbol1
inc si
JMP readNextChar1
storeEndSymbol1:
mov al,'$'
mov [si], al
ret
placeEndSymbolForUser endp
; this proc store '$' symbol at the end of user password string
placeEndSymbolForPsw proc
; for userPassword
mov si, offset regPssw
readNextChar2:
mov al,[si]
cmp al,0DH
JE storeEndSymbol2
inc si
JMP readNextChar2
storeEndSymbol2:
mov al,'$'
mov [si], al
ret
placeEndSymbolForPsw endp
; this procedure will find the length of given string, which si register points
checkLength proc
mov cx, 0 ; store length of string
readNextChar3:
mov al,[si]
cmp al, '$'
JE stopCheckLength
inc si
inc cx ; increment the length of string
JMP readNextChar3
stopCheckLength:
ret
checkLength endp
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV AH, 0 ; set video mode
MOV AL, 2 ; set row cols 80 x 26
INT 10H
CLEARSCREEN
;-----------DISPLAY WELCOME MESSAGE----------
PRINTSTRING welMsg
newline
;--------------------------------------start of sign in sign up modulus----------------------
;---------display main menu and enter option----------
loginmenu:
newline
PRINTSTRING loginmessage0
newline
PRINTSTRING loginmessage1
newline
PRINTSTRING loginmessage2
newline
PRINTSTRING exitloginmessage
newline
PRINTSTRING loginmessage4
INPUTOPTION
;--------check entered option-----------------
cmp al,'1' ; if choice = '1' then create a new account
JE oor1
cmp al,'2' ; if '2' then login account
JE oor2
cmp al, '3' ; if '3' then exit
JE oor3
newline
;------------validation error option-----------------
PRINTSTRING loginmessage5 ;else print invalid message
newline
jmp loginmenu
oor1:
jmp newuser
oor2:
jmp oldUser
oor3:
jmp exit
;------------------LOGIN OLD ACCOUNT---------------
olduser:
CLEARSCREEN
NEWLINE
PRINTSTRING loginmessage6 ;display "********login*********
NEWLINE
PRINTSTRING loginmessage7 ;display "Enter Username"
; read username from user through keyboard
STORING regUser
NEWLINE
PRINTSTRING loginmessage8 ;display "Enter password"
STORING regPssw
;place '$' at the end of username and password
call placeEndSymbolForUser
call placeEndSymbolForPsw
;--------------check username and passwords----------------
CALL isValidAccountDetails
cmp ax, 1
JE loginSuccessfullyCustomer
;else
PRINTSTRING invalidAccountInfo ;username and password is nto matched with database
NEWLINE
PRINTSTRING IMSG ;DISPLAY "ACCESS DENIED'
loginSuccessfullyCustomer:
PRINTSTRING successfullLoginMsg
NEWLINE
PRINTSTRING VMSG ;DISPLAY "ACCESS GRANTED'
NEWLINE
CLEARSCREEN
JMP mainmenu ;go to main menu
;----------------Register new account------------------
newuser:
NEWLINE
MOV AX, totalUsr
cmp ax, 6 ;check if database whether is full or not(limit is 6)
JNE createAcc ; if it is not full, then create new account
PRINTSTRING databaseFullMsg
NEWLINE
JMP mainmenu ;go to main menu
createAcc:
PRINTSTRING loginmessage9 ; display "Set your user account(username): "
STORING regUser
call placeEndSymbolForUser
call isValidUserName
cmp aX, 1
JNE oor4
mov si, offset regUser
call checkLength
cmp cx, 5
JBE oor5
oor4:
jmp invalidacc
oor5:
jmp invalidUserLength
askPsw:
PRINTSTRING loginmessage10 ; display "Set your password: "
;get password from user
STORING regPssw
call placeEndSymbolForPsw
mov si, offset regPssw ; check password length
call checkLength
cmp cx, 8 ; if password length is <=8 then invalid password lengths
JBE oor6
;else create user account
; createAccount
NEWLINE
PRINTSTRING confirmAccountMsg0 ; display "Confirm to create the account(y/n): "
NEWLINE
PRINTSTRING confirmAccountMsg ; display "Confirm to create the account(y/n): "
INPUTOPTION ; read character from keyboard
cmp al, 'y' ; check if al is equal 'y' or 'Y' is entered then create account
JE yesCreateAccount
cmp al,'Y'
JE yesCreateAccount
; else account can't be created
NEWLINE
PRINTSTRING accountFailCreatedMsg ; display "Account create fail"
NEWLINE
JMP loginmenu ; goto main menu
oor6:
jmp invalidPswLength
yesCreateAccount:
call createAccount
NEWLINE
PRINTSTRING accountCreatedMsg
NEWLINE
mov ah,1
int 21h
JMP oldUser ; goto login
invalidAcc:
PRINTSTRING repeatAccMsg ; display "Sorry the account has been used, Try other"
NEWLINE
JMP createAcc ; ask again for username
invalidUserLength:
PRINTSTRING invalidLengthForUsername ; display "Invalid username, Username Length must be greater than 5 characters"
NEWLINE
JMP createAcc ; ask again for username
invalidPswLength:
PRINTSTRING invalidPassError ; display "Sorry your password dose not fulfil, Password Length must be greater than 8 characters"
NEWLINE
JMP askPsw ; ask again for user password
exit:
call end_prog
end_prog:
PRINTSTRING endMsg
mov ah, 4ch
int 21h
ret
;--------------------------------end of sign in sign up modulus----------------------
;----------------------display main menu after login----------------
mainmenu:
PRINTSTRING welMsg ;temp msg
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
Here is the problem that I facing now:
Although it's a bit long, I hope u guys can take time for looking at it. This is my assignment.
CodePudding user response:
An unfortunate fall-through problem
call isValidUserName cmp aX, 1 JNE oor4 mov si, offset regUser call checkLength cmp cx, 5 JBE oor5 <=== All is well: Need to jump to `askPsw` here oor4: jmp invalidacc oor5: jmp invalidUserLength askPsw:
The code is missing a crucial jmp
. For now the code falls through in oor4 eventhough the new username is long enough.
Next code solves the problem and avoids adding yet another jump to the program (mainly by inverting the condition):
call isValidUserName ; -> AX=[0=NOK, 1=OK]
cmp ax, 1
JNE oor4
mov si, offset regUser
call checkLength ; -> CX
cmp cx, 5
JA askPsw
oor5:
jmp invalidUserLength
oor4:
jmp invalidacc
askPsw: