[Computers and UNIX Assembly Principles_] - Experimentation Report 2 [ ⭐ Implementation of User Login Authenticator+Support for Backoff Function ⭐ )


Log in!⌨️

Links to previous article: [Computers and UNIX Assembly Principles]-Example of Assembly Language Programming [Three Binary Conversions].
Next article link: 🚧 🚧 …

Zero. Preview of results


Note: This is the case when both the account (with echo) and password (without echo) are entered correctly. Other incorrect entries will show other prompts.


1. Implementation of User Logon Authentication Program

1. Title Description:

After the program executes, give an operation hint, ask the user to enter the user and password; when the user enters the password, the program does not echo the input characters; only when the user enters the same user name, password characters and the program-defined strings, will the welcome interface be displayed and returned to DOS. The interface color is customized (color or black and white).


2. Design ideas:

@ Built-in the account and password in advance in the data section. At the beginning of the program, enter the account first. If the account exists in the background, continue to enter the password, and display the welcome screen after the password is correct. [In addition, I added an input mechanism that supports the "fallback" character.)


3. Design flowchart:


4. Code implementation:

.586
;----------Macro Instructions with Parameters-----------
Input MACRO Fun_Num, Address
LOCAL   LOOP1, LOOP2				; LOCAL Pseudo Instructions
		MOV IN_LEN, 00H
		
LOOP1:	MOV AH, Fun_Num			; Get 1 character from keyboard(Function number 01 H/07H→Yes/No echo)
		INT 21H
		MOV DL, AL
		MOV BL, AL
		MOV BYTE PTR [Address], DL
		INC Address
		INC IN_LEN					; Enter password length + 1
		SUB BYTE PTR DL, 08H		; Compare with Backspace Symbol
		JNZ LOOP2					; Jump if not equal
		SUB Address, 02H			
		SUB IN_LEN, 02H				; Enter password length - 2
		MOV DL, ' '					; Replace the wrong input with a space character
		MOV AH, 2
		INT 21H
		MOV DL, 08H					; Return Again(Space character)That is, the cursor moves one bit to the left
		MOV AH, 2
		INT 21H
		
		JMP LOOP1
LOOP2:  MOV DL, BL					; key! Need to be given again DL assignment(Writable experiment Bug)
		SUB BYTE PTR DL, 0DH		; Compare with Enter Symbol
		JNZ LOOP1					; Jump if not equal
SUB IN_LEN, 01H				; Last but not least'Carriage Return Symbol'Quantity 1 minus
ENDM

;----------Data segment-----------------
DATA 	SEGMENT USE16
		USER 	DB	'NJUPT'
		USER_LEN 	EQU $-USER
		PAS 	DB '123456'
		PAS_LEN EQU $-PAS
		Hint_1 	DB 'Pleasa input the user:(End with Enter character)', 0DH, 0AH,'$'
		Hint_2 	DB 'Pleasa input the passward(No echo):', 0DH, 0AH,'$'
		Hint_3 	DB 0DH, 0AH, '   +------------------------+', 0DH, 0AH
				DB '   |                        |', 0DH, 0AH
				DB '   |                        |', 0DH, 0AH			   
				DB '   |        Welcome!        |', 0DH, 0AH
				DB '   |                        |', 0DH, 0AH
				DB '   |                        |', 0DH, 0AH
				DB '   +------------------------+', 0DH, 0AH
				DB '            | | |         ', 0DH, 0AH
				DB '            | | | ____________       ', 0DH, 0AH
				DB '            | | |/            \  ', 0DH, 0AH
				DB '      +-------------------+    \     ', 0DH, 0AH
				DB '     / ................../    /|\   ', 0DH, 0AH
				DB '    /.....===.........../     \_/ ', 0DH, 0AH
				DB '   +-------------------+         ', 0DH, 0AH
				DB '$'
		Err_1 	DB 'The user does not exist!', 0DH, 0AH,'$'
		Err_2 	DB 'Wrong passward!', 0DH, 0AH,'$'
		IN_1 	DB 100 DUP(?)
		IN_2 	DB 100 DUP(?)
		IN_LEN 	DW 00H
DATA	ENDS
;----------Code snippet-----------------
CODE	SEGMENT USE16
ASSUME	CS:CODE, DS:DATA
BEG:	MOV 	AX, DATA
		MOV 	DS, AX
		
;-----------User name handling-------------
		MOV 	DX, OFFSET Hint_1
		CALL DISP
		MOV 	SI, OFFSET IN_1
		Input 01H, SI 	
		
		MOV 	SI, OFFSET IN_1
		MOV 	DI, OFFSET USER
		MOV 	CX, USER_LEN
		MOV 	AX, IN_LEN
		SUB     AX, BYTE PTR CX
		JNZ 	ERROR_1				; Jump if user length does not match
LOOP3:	MOV 	AL, [SI]
		MOV 	AH, [DI]
		SUB 	AH, AL	
		JNZ 	ERROR_1
		INC	 	SI
		INC 	DI
		LOOP LOOP3
;-----------Password Processing----------------
		MOV 	DX, OFFSET Hint_2
		CALL DISP
		
		MOV 	SI, OFFSET IN_2
		Input 07H, SI
		MOV 	SI, OFFSET PAS
MOV 	CX, PAS_LEN
		MOV 	AX, IN_LEN
		SUB     AX, BYTE PTR CX
		JNZ 	ERROR_2				; Jump if password length does not match
LOOP4:	MOV 	AL, [SI]
		MOV 	AH, [DI]
		SUB 	AH, AL	
		JNZ 	ERROR_2
		INC 	SI
		INC 	DI
		LOOP LOOP4
			
		MOV 	DX, OFFSET Hint_3
		CALL DISP
		
		MOV 	AH, 4CH
		INT 	21H

;----------User name error---------------
ERROR_1:MOV 	AH, 09H
		MOV 	DX, OFFSET Err_1	
		INT 	21H					
		MOV 	AH, 4CH
		INT 	21H

;----------Password error-----------------
ERROR_2:MOV	 	AH, 09H
		MOV 	DX, OFFSET Err_2	
		INT 	21H					
		MOV 	AH, 4CH
		INT 	21H
;----------String Display Subprogram---------
DISP PROC
		MOV 	AH, 09H
		INT 	21H
		RET
DISP ENDP	
CODE ENDS
END BEG 
; Test Account NJUPT(Numbers need to be used'~'Numbers in that row)  Password 123456
; Support fallback

5. Operation results:


6. Main issues to be solved during debugging:

Considering that when a password is actually entered, there may be an input error and then "fallback". Then I improved the mechanism. A detailed problem occurred during the design process. That is, first I didn't use the Back Character (08H) as a character, so the SI was reduced by only 1 - which is equivalent to "the cursor only goes back to the Back Character position, not to the character position where the input error occurred".
_Later, after my single step debugging, I found a problem. Simply reduce the SI by 2 to solve the problem.


2. Reference Appendix

[1] Principles and Interface Technologies of Micro-Computers (Mushboard)
tsinghua university press

[2] Assembly Language Programming (2nd Edition)

[3] "Instructions for Experiment of Microcomputer Principles and Interface Technologies (2nd Edition)"

[4] List of ASCII codes, ASCII code comparison table
Links: http://c.biancheng.net/c/ascii/.

Links to previous article: [Computers and UNIX Assembly Principles]-Example of Assembly Language Programming [Three Binary Conversions].

Next article link: 🚧 🚧 …

⭐️ ⭐️

Tags: Unix

Posted on Wed, 20 Oct 2021 12:11:59 -0400 by twinedev