Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to add a password
prompt to a simple batch file. The prompt should ask users for a three-character password before executing the rest of the batch file. Anyone?

Batch files are not good for password requests. That's because the password will have to be on the source code, so anyone can edit the batch file and see what is the password!
Anyway, here goes a batch which will ask for a password. This one will only accept numbers, though that can be changed. The numbers typed will appear on the screen as asterisks.
===== BATCH SCRIPT BEGIN =====
:: Leonardo Pignataro (secret_doom@hotmail.com)
:: Numeric password request
:: Displays asterisks instead of typed numbers
:: Disabled CTRL+C (CTRL+BREAK still works)
@echo off:: Set password below. Do also
:: set the password's length.
SET REAL_PASS=123
SET REAL_LENGTH=***:: Thanks to Laurence Soucy for the following assembler code
echo e100 B4 00 CD 16 88 E0 B4 4C CD 21> %temp%.\scan.com
for %%? in (rcx A w q) do echo %%?>> %temp%.\scan.com
type %temp%.\scan.com |DEBUG %temp%.\scan.com > nul:pre
for %%? in (pass length) do set user_%%?=:loop
set input=
cls
echo Type password: %user_length%
if "%user_pass%"=="%real_pass%" goto granted
if "%user_length%"=="%real_length%" goto denied
call %temp%.\scan.com
if errorlevel=2 if not errorlevel=3 set input=1
if errorlevel=3 if not errorlevel=4 set input=2
if errorlevel=4 if not errorlevel=5 set input=3
if errorlevel=5 if not errorlevel=6 set input=4
if errorlevel=6 if not errorlevel=7 set input=5
if errorlevel=7 if not errorlevel=8 set input=6
if errorlevel=8 if not errorlevel=9 set input=7
if errorlevel=9 if not errorlevel=10 set input=8
if errorlevel=10 if not errorlevel=11 set input=9
if errorlevel=11 if not errorlevel=12 set input=0
if errorlevel=71 if not errorlevel=72 set input=7
if errorlevel=72 if not errorlevel=73 set input=8
if errorlevel=73 if not errorlevel=74 set input=9
if errorlevel=75 if not errorlevel=76 set input=4
if errorlevel=76 if not errorlevel=77 set input=5
if errorlevel=77 if not errorlevel=78 set input=6
if errorlevel=79 if not errorlevel=80 set input=1
if errorlevel=80 if not errorlevel=81 set input=2
if errorlevel=81 if not errorlevel=82 set input=3
if errorlevel=82 if not errorlevel=83 set input=0
if "%input%"=="" goto loop
set user_length=*%user_length%
set user_pass=%user_pass%%input%
goto loop:granted
:: Here goes the code which needs
:: authorization to be runned.
echo Access granted.
goto pass_end:denied
echo Access denied.
:: Uncomment following line in order to
:: keep asking user the password
:: GOTO PRE
goto pass_end:pass_end
for %%? in (pass length) do set user_%%?=
for %%? in (pass length) do set real_%%?=
del %temp%.\scan.com
===== BATCH SCRIPT END =====Watch out for line wrapping!
Read commented lines in order to change the password (this one is 123). This batch was tested under Win98SE.
Another way (simpler) to ask for password would be to ask user input (like shown in my FAQ #06 and #07) and check if the input is equal to the password.
What do you think about this batch above?
-- Leonardo Pignataro - Secret_Doom --
secret_doom@hotmail.com
www.batch.hpg.com.br

![]() |
In BAT file: test if Wind...
|
Non-System disk or disk e...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |