Hidden Password in Batch

Introduction: Hidden Password in Batch

About: 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 to become a programmer, although in what category is still a mystery (al…

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

:start
@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

:erase
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

:login
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
cls
echo %tries% tries remaining
echo.
echo Please Enter your password.
if %input% neq 0 echo %input%
choice /c abcdefghijklmnopqrstuvwxyz1234567890 /n
cls
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

:compile
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

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

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

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

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

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

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

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

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

:2
set password=%let2%%let1%
goto check

:1
set password=%let1%
goto check

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

:reward
rem Put the rest of your code here
cls
echo Correct!
pause
exit

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

:punish
rem Put your punishment here
cls
echo Too many incorrect passwords
echo.
pause
exit

:create
cls
echo Create user
echo.
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"
cls
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

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.

Be the First to Share

    Recommendations

    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • Big and Small Contest

      Big and Small Contest
    • Make It Bridge

      Make It Bridge

    14 Comments

    0
    NotePro
    NotePro

    1 year ago

    Nice idea. Could be majorly shortened though.

    0
    LisaJ130
    LisaJ130

    Question 4 years ago on Step 1

    Hi

    Would it be possible for you to make this code with a 20 characters
    length, capital letters, case-sensitive and with the ability to accept
    two passwords, not to change from one to another since I understand that
    we can do that by editing the pass.bat file, but instead to perform
    different tasks with different passwords. For example, typing 123 will
    open file “A” and typing 123456 will open file “B” I'll appreciate very
    much if you could do this and send it for me.


    My contact email is lisa.johnson.0801@gmail.com

    0
    SougataT
    SougataT

    5 years ago

    Thank you...
    This help me a lot...

    0
    wilderness tech
    wilderness tech

    6 years ago

    hey what environment variable did you not use?

    0
    llopez26
    llopez26

    9 years ago

    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!

    0
    Prof. Pickle
    Prof. Pickle

    Reply 9 years ago on Introduction

    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.

    0
    llopez26
    llopez26

    Reply 9 years ago on Introduction

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

    0
    TDACHO
    TDACHO

    9 years ago on Introduction

    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!

    0
    Prof. Pickle
    Prof. Pickle

    Reply 9 years ago on Introduction

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

    0
    TDACHO
    TDACHO

    9 years ago on Introduction

    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

    0
    Prof. Pickle
    Prof. Pickle

    Reply 9 years ago on Introduction

    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.

    0
    Prof. Pickle
    Prof. Pickle

    Reply 9 years ago on Introduction

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