How to Make an Easy Password Protected Batch File

Introduction: How to Make an Easy Password Protected Batch File

This is a VERY simple passowrd protected batch, lets say i had a batch file that would open a new text file (my_diary.txt) but didnt want people to get to it easly, i would want a password. this is an easy way to do it, you would only really need to know how to use variables...

this is the batch file code to open my txt document:

@echo off

echo %variable% > my_diary.txt

Now i want to place a password on the file, using the variable "variable".

to do so we need to tell the computer to ask for a password, and only open the file if the user types in that word, this is how you can do it (i put in the code assuming you know what the code means)

@echo off

:start

echo Paswword:

set /p variable=

if %variable%==password goto open

if NOT %variable%== password goto fail

:open

echo %variable% > my_diary.txt

:fail

echo Wrong password!!

pause

goto start

the password is "password" but that can always be changed, this will keep asking for the password untill you get it right.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Be the First to Share

    Recommendations

    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Finish It Already Speed Challenge

      Finish It Already Speed Challenge

    Discussions