-
Notifications
You must be signed in to change notification settings - Fork 1
/
4. PASSWORD'S VALIDATION CEHCK.asm
147 lines (104 loc) · 4.19 KB
/
4. PASSWORD'S VALIDATION CEHCK.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
; THIS ASSEMBLY PROGRAM IS FOR CHECKING VALID PASSWORD
; A PASSWORD IS VALID WHEN IT FITS THE FOLLOWING CRITERIA
; AT LEAST:
; 1. ONE UPPERCASE LETTER ( ascii: 41H-5AH )
; 2. ONE LOWERCASE LETTER ( ascii: 61H-7AH )
; 3. AT LEAST ONE DIGIT ( ascii: 30H-39H )
; SCANNING FOR INPUT IS TERMINATED WHEN A ASSCII VALUE IS FOUND OUTSIDE THE RANGE ( 21H-7EH )
.MODEL SMALL
.STACK 100H
.DATA
VALID_UPPERCASE DB 0H
VALID_LOWERCASE DB 0H
VALID_DIGIT DB 0H
CR EQU 0DH
LF EQU 0AH
MSG DB 'ENTER THE PASSWORD: $'
VALID_PASS_MSG DB CR, LF, 'Valid Password$'
INVALID_PASS_MSG DB CR, LF, 'Invalid Password$'
.CODE
MAIN PROC
; DATA SEGMENT INITIALIZATION
MOV AX, @DATA
MOV DS, AX
; LOOP FOR TAKING INPUT UNTIL A UNACCEPTABLE CHARACTER IS FOUND
LEA DX, MSG
MOV AH, 9
INT 21H
DO_LOOP:
MOV AH, 1
INT 21H
;MOV CHAR, AL
; CHECH FOR UPPERCASE LETTER
UPPERCASE:
; CHECK IF THE CHARACTER IS IN 'A-Z'
CMP AL, 'A'
; IF LESS THAN 'A' THEN CHECK FOR DIGIT
JL DIGIT
CMP AL, 'Z'
; IF GREATER THAN 'Z' THEN CHECK FOR LOWERCASE LETTER
JG LOWERCASE
; IF IN RANGE 'A-Z' SET VALID_UPPERCASE TO 1
MOV DL, 1H
MOV VALID_UPPERCASE, DL
JMP DO_LOOP
; CHECH FOR LOWERCASE LETTER
LOWERCASE:
; CHECK IF THE CHARACTER IS IN 'A-Z'
CMP AL, 'a'
; IF LESS THAN 'A' THEN CHECK FOR DIGIT
JL DIGIT
CMP AL, 'z'
; IF GREATER THAN 'Z' THEN CHECK FOR LOWERCASE LETTER
JG OTHERS
; IF IN RANGE 'A-Z' SET VALID_UPPERCASE TO 1
MOV DL, 1H
MOV VALID_LOWERCASE, DL
JMP DO_LOOP
; CHECK FOR VALID DIGIT
DIGIT:
; IF IT IS IN RANCE '0-9'
CMP AL, '0'
JL OTHERS
CMP AL, '9'
JG OTHERS
MOV DL, 1H
MOV VALID_DIGIT, DL
JMP DO_LOOP
; CHECK FOR AT LEAST THE CHARACTER IS VALID
OTHERS:
CMP AL, 21H
JL CHECK_VALIDITY
CMP AL, 7EH
JG CHECK_VALIDITY
JMP DO_LOOP
; AFTER SCANNING THE PASSWORD SUCCESSFULLY CHECK PASSWORD VALIDITY
CHECK_VALIDITY:
; CHECK IF VALID_UPPERCASE IS NOT '0H'
CMP VALID_UPPERCASE, 0H
JE INVALID_PASSWORD
; CHECK IF VALID_UPPERCASE IS NOT '0H'
CMP VALID_LOWERCASE, 0H
JE INVALID_PASSWORD
; CHECK IF VALID_UPPERCASE IS NOT '0H'
CMP VALID_DIGIT, 0H
JE INVALID_PASSWORD
; AT THAT POINT PASSWORD IS VALID
JMP VALID_PASSWORD
; SHOW MESSAGE FOR INVALID PASSWORD
INVALID_PASSWORD:
LEA DX, INVALID_PASS_MSG
MOV AH, 9
INT 21H
JMP DOS_INTERRUPT_EXIT
; SHOW MESSAGE FOR VALID PASSWORD
VALID_PASSWORD:
LEA DX, VALID_PASS_MSG
MOV AH, 9
INT 21H
; DOS INTERRUPT WITH EXIT AND GIVE CONTROL TO OPERATING SYSTEM
DOS_INTERRUPT_EXIT:
MOV AH, 4CH
INT 21H
MAIN ENDP
END MAIN