Introduction: Hidden Password in Batch

Picture of Hidden Password in Batch

In this instructable, I will provide you with a segment of a program that you can use to make a password lock on you batch program. DON'T LEAVE YET. You may be thinking: "I've seen heaps of these, I'll just leave now". Don't.

My version is different, and, in my opinion, better than those of others. The main, and only difference, is that when you enter your password, instead of letters showing up, asterisks (*) do instead.

There are a few drawbacks with this though. The code is longer than most, the password must be under a certain amount of letters and the password is case insensitive.

It can only contain letters (a-z) and numbers (0-9). 

Oh, and also, sorry for spamming instructables recently, I'm having so many ideas. Just bear with my creative flow, until it runs out, that is.

Here it is:

Step 1: Code

Picture of Code

@echo off
setlocal enableextensions enabledelayedexpansion
color f0
title hidden password tester

if not exist pass.bat goto create

call pass.bat

set let1=na
set let2=na
set let3=na
set let4=na
set let5=na
set let6=na
set let7=na
set let8=na
set let9=na
set let10=na
set input=0
set tries=3

set code2=%pass%q234567890

set char1=!code2:~0,1!
set char2=!code2:~1,1!
set char3=!code2:~2,1!
set char4=!code2:~3,1!
set char5=!code2:~4,1!
set char6=!code2:~5,1!
set char7=!code2:~6,1!
set char8=!code2:~7,1!
set char9=!code2:~8,1!
set char10=!code2:~9,1!
set char11=!code2:~10,1!

if %char2% equ q set num=1

if %char3% equ q set num=2

if %char4% equ q set num=3

if %char5% equ q set num=4

if %char6% equ q set num=5

if %char7% equ q set num=6

if %char8% equ q set num=7

if %char9% equ q set num=8

if %char10% equ q set num=9

if %char11% equ q set num=10

set count=%num%

set round=-1

set /a num=%num%+1
goto login

set round=-1
set let1=na
set let2=na
set let3=na
set let4=na
set let5=na
set let6=na
set let7=na
set let8=na
set let9=na
set let10=na
set input=0
set /a num=%count%+1

set /a num=%num%-1
set /a round=%round%+1
if %round% equ 1 set input=*
if %round% equ 2 set input=**
if %round% equ 3 set input=***
if %round% equ 4 set input=****
if %round% equ 5 set input=*****
if %round% equ 6 set input=******
if %round% equ 7 set input=*******
if %round% equ 8 set input=********
if %round% equ 9 set input=*********
if %round% equ %count% goto compile
echo %tries% tries remaining
echo Please Enter your password.
if %input% neq 0 echo %input%
choice /c abcdefghijklmnopqrstuvwxyz1234567890 /n
if %errorlevel% equ 1 set let%num%=a
if %errorlevel% equ 2 set let%num%=b
if %errorlevel% equ 3 set let%num%=c
if %errorlevel% equ 4 set let%num%=d
if %errorlevel% equ 5 set let%num%=e
if %errorlevel% equ 6 set let%num%=f
if %errorlevel% equ 7 set let%num%=g
if %errorlevel% equ 8 set let%num%=h
if %errorlevel% equ 9 set let%num%=i
if %errorlevel% equ 10 set let%num%=j
if %errorlevel% equ 11 set let%num%=k
if %errorlevel% equ 12 set let%num%=l
if %errorlevel% equ 13 set let%num%=m
if %errorlevel% equ 14 set let%num%=n
if %errorlevel% equ 15 set let%num%=o
if %errorlevel% equ 16 set let%num%=p
if %errorlevel% equ 17 set let%num%=q
if %errorlevel% equ 18 set let%num%=r
if %errorlevel% equ 19 set let%num%=s
if %errorlevel% equ 20 set let%num%=t
if %errorlevel% equ 21 set let%num%=u
if %errorlevel% equ 22 set let%num%=v
if %errorlevel% equ 23 set let%num%=w
if %errorlevel% equ 24 set let%num%=x
if %errorlevel% equ 25 set let%num%=y
if %errorlevel% equ 26 set let%num%=z
if %errorlevel% equ 27 set let%num%=1
if %errorlevel% equ 28 set let%num%=2
if %errorlevel% equ 29 set let%num%=3
if %errorlevel% equ 30 set let%num%=4
if %errorlevel% equ 31 set let%num%=5
if %errorlevel% equ 32 set let%num%=6
if %errorlevel% equ 33 set let%num%=7
if %errorlevel% equ 36 set let%num%=8
if %errorlevel% equ 35 set let%num%=9
if %errorlevel% equ 36 set let%num%=0
goto login

if %let1% equ na goto 9
if %let2% equ na goto 1
if %let3% equ na goto 2
if %let4% equ na goto 3
if %let5% equ na goto 4
if %let6% equ na goto 5
if %let7% equ na goto 6
if %let8% equ na goto 7
if %let9% equ na goto 8
goto 10

set password=%let10%%let9%%let8%%let7%%let6%%let5%%let4%%let3%%let2%%let1%
goto check

set password=%let9%%let8%%let7%%let6%%let5%%let4%%let3%%let2%%let1%
goto check

set password=%let8%%let7%%let6%%let5%%let4%%let3%%let2%%let1%
goto check

set password=%let7%%let6%%let5%%let4%%let3%%let2%%let1%
goto check

set password=%let6%%let5%%let4%%let3%%let2%%let1%
goto check

set password=%let5%%let4%%let3%%let2%%let1%
goto check

set password=%let4%%let3%%let2%%let1%
goto check

set password=%let3%%let2%%let1%
goto check

set password=%let2%%let1%
goto check

set password=%let1%
goto check

if %password% neq %pass% goto bad
if %password% equ %pass% goto reward

rem Put the rest of your code here
echo Correct!

echo Incorrect!
set /a tries=%tries%-1
if %tries% equ 0 goto punish
echo Press any key to try again
pause >nul
goto erase

rem Put your punishment here
echo Too many incorrect passwords

echo Create user
echo Password must only contain characters from a-z and 0-9. Password is non case-sensitive. CANNOT EXCEDE 10 CHARACTERS!
set /p pass=Password:
echo set pass=%pass%> "pass.bat"
goto start

Feel free to ask me to modify the program and send it to you. I can add or change features to:
1. Change the length of the password
2. Make it case-sensitive (might take a while)
3. ...And many others, just ask!

Step 2: Credit

Picture of Credit

Because I made this with the intent of other people using it, you may use it without permission, so long as it is not for commercial gain AND you give me credit. Also, could you please send me a link so I can admire your work.

P.S: Remember when I said it was longer than normal ones? Well, it's 227 lines compared to the 20 you could probably do it in. It's worth it, in my opinion. 

P.S.S: If you don't understand something in the code, ask me about it.


wilderness tech (author)2016-11-28

hey what environment variable did you not use?

Batchcc (author)2015-11-13

There is an easier way to do this here


llopez26 (author)2013-12-27

Very useful! It is possible to handle multiple pass? Example pass1, pass2, pass3, etc. in the same batch? That way I can replace Choice? I need to use it in xp/7/8 Thank you!

Prof. Pickle (author)llopez262013-12-27

Like most of these situations, it is possible to reconstruct it without using the choice command, but it looks and feels a whole heap better with it. Also, it wouldn't be as effective as the letters would show up before you press enter. My suggestion is to try to download choice.exe.

llopez26 (author)Prof. Pickle2013-12-27

why not think of that before! what about the multiple pass?

TDACHO (author)2013-08-02

Thanks for explanation... In meantime i made similar script with the same purpose (hide input code) and I made it case sensitive! With the choice command type /CS at the end. So it will treat choices as case sensitive.
Just like this:
"choice /c qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890 /n /CS"

Hope it helps!

Prof. Pickle (author)TDACHO2013-08-02

As a little additive, you could shorten the code tremendously by adding in a compiler with a few FOR loops.

TDACHO (author)2013-07-29

Thanks! This is great! It was very helpful! I'm not pro with batch scripts but i know many commands and i know how to use them... So there is couple of things which is unknown for me... Like "set char1=!code2:~0,1!".... Can you please explain me purpose of this command... :D

Prof. Pickle (author)TDACHO2013-08-02

Well, it's basically just string manipulation. You set the value of "char1" to the the first character in the variable "code2". Think of "0,1" as coordinates, if it helps. The first digit is the offset (how many characters from the start) and the second digit as how many characters to take.

Dostips has some nice examples and practical uses.

lizzyd710 (author)2013-06-12

How do you change the password?

Prof. Pickle (author)lizzyd7102013-06-12

Once you've set the password it can be changed by editing the pass.bat file.

About This Instructable




Bio: I enjoy anything to do with computers. I have made some interesting scripts, and I am constantly improving my skill set. One day I hope ... More »
More by Prof. Pickle:How to Create your own Commands with BatchStart a batch file completely hiddenTips on how to find errors in code (focused on DOS)
Add instructable to: