Last active
May 14, 2024 02:09
-
-
Save kenedii/bc7a4adb326e54ab469a02ebd3308e51 to your computer and use it in GitHub Desktop.
Password screen where user enters a password and it grants/denies the user access. MASM32 x86 Assembly code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include \masm32\include\masm32rt.inc | |
; password is: masm32 | |
;________________________________________ | |
; Note: This code is not safe for prod. | | |
; as password is in plaintext when exe | | |
; is examined by a hex viewer. | | |
;________________________________________ | |
.data | |
hex_pw db 6Dh,61h,73h,6Dh,33h,32h,00h ; password stored as hex, ending with 00h | |
user_input db 1000 dup(?) | |
enter_password_screen db "Enter the password: ",0 ; 13,10 for newline | |
incorrect_pw_screen db "Incorrect password. ",13,10,0 | |
correct_pw_screen db "Correct password.",13,10,0 | |
display_message db "Display this message when the user enters the right password",0 | |
.code | |
start: | |
invoke StdOut, offset enter_password_screen ; Prompt the user to enter a password. | |
push 1000 ; Max number of bytes user str input can be | |
push offset user_input | |
call StdIn ; Accept user input for a password | |
push offset hex_pw | |
push offset user_input | |
call crt__stricmp ; Compares the two strings. Sets the zero flag to eax if they are equal strings | |
cmp eax, 0 ; If eax=0, strings are equal so we grant the user access | |
je accessGranted | |
jne accessDenied | |
accessGranted: | |
invoke StdOut, offset correct_pw_screen | |
invoke StdOut, offset display_message | |
jmp endProg ; Jump to end of the program after successful authentication | |
accessDenied: | |
invoke StdOut, offset incorrect_pw_screen | |
mov user_input, 0 ; Replace the users input with zeros | |
jmp start ; Jump to ask user for password again if they get it wrong | |
endProg: | |
invoke ExitProcess, 0 | |
end start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment