Password Batch

92K1629

Intro: Password Batch

Hey there Instructables community! I'v decided to share to you how to make a very simple Password Batch file that will run through the command prompt. This is my very first Instructable, so please be gentle with the comments, but tell me if theres anything that needs to be added or clarified. Ready? LETS DO THIS!

STEP 1: What You Need to Know

First off, you need some basic training in batch scripting if you have no clue as to what your doing!
If you already know, please, feel free to skip ahead to step 2. But here I will give you some of the basic "vocab" you will see in many basic batch files.
To start, you will almost always need to start your batch file off with this first line
"@ echo off" This line allows you to create text in your batch file with the "Echo" command, and it makes sure you don't see the "echo" part while the file is running.
"Echo" command is the syntax that allows for text to be seen in the batch file. simply use this line of code to create any text you wish
"Echo Your Text Here"
The third most common script you will see in this instructable is the "ping localhost" line. What this does is wait a set amount of time (in seconds) until the next line of script can be run. The command is as follows...
"ping localhost -n {time in seconds here} >nul"
Then to close any script of the entire program, depending on where you put this code, use this...
"cls"
this really doesn't need to be explained too much more.
And finally, before any of this can begin, you must have Notepad open in order to do any scripting.
Pleas continue to Step 2.

STEP 2: The Scripting

Now, for you more advanced scriptors, you may wish to just follow the code and type it in yourself s for a more "self satisfaction" feeling, but if your anything like me, and your too lazy and just want the project done to keep your annoying siblings, parents, or roommates out of your system, then just simple copy and paste the code into notepad, and make sure you save it with an ending of ".bat" instead of ".txt" this will change it into a batch file that you can run. Here is the code for ya! What this does is gives you a total of 5 tries to get the password right. Should a wrong password be entered after those five tries, well, I've given the program a bit of a surprise. Jurassic Park fans will notice that under the ":penalty" codes, it will spell out "Ah Ah Ah, You Didn't Say The Magic Word" over and 5 times until "Shutdown" command is activated. Simple, No?

@ Echo off
color C
Title Welcome Back
set tries=6
:top
cls
set /a tries=%tries% -1
if %tries%==0 (
goto penalty
)
Echo You have %tries% attempts left.
Echo Please enter your password to proceed
set /p password=
if %password%==Your Password Here (
echo Welcome Your Name
ping localhost -n 5 >nul
cls
Echo CONNECTED!
pause
cls
) else (
goto top
)
goto top
:penalty
echo A
ping localhost -n .15 >nul
cls
echo Ah
ping localhost -n .15 >nul
cls
echo Ah A
ping localhost -n .15 >nul
cls
echo Ah Ah
ping localhost -n .15 >nul
cls
echo Ah Ah A
ping localhost -n .15 >nul
cls
echo Ah Ah Ah
ping localhost -n .15 >nul
cls
echo Ah Ah Ah,
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, Y
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, Yo
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You D
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Di
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Did
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn'
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't S
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Sa
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say T
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say Th
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The M
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Ma
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Mag
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magi
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic W
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Wo
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Wor
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word.
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word..
ping localhost -n .15 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word...
ping localhost -n 5 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word...
ping localhost -n 5 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word...
ping localhost -n 5 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word...
ping localhost -n 5 >nul
cls
echo Ah Ah Ah, You Didn't Say The Magic Word...
ping localhost -n 5 >nul
cls
shutdown -s -f -t 15 -c "Next Time, Just Ask Me For The Magic Word"

STEP 3: Now for the Fun Part

Ok guys and gals, i have provided the code, as well as an explanation of what it does. I want to point out that this instructable was created FOR INSTRUCTIONAL PURPOSES ONLY! What you do with this script is solely on you, and not Me, or this wonderful site. I want to take a moment and remind all coders and scriptors that inserting and running of malicious files or data on anyone's computer besides your own is ILLEGAL! And, depending on your age, can end you up in Prison! This batch job will cause no damage to the files or computers that it is placed on, it is meant as pure fun, as well as security.
Now, to get this batch file to run upon logon, all you have to do is go "Control Panel" then to "Performance and Maintenance" then to "Scheduled Tasks" from there it's a simple process to schedule the batch file to run when you logon.

STEP 4: Wrap Up

OK, now if you did everything as I have said, this program should run with no issues! .
Now, to take it one step further you can convert the .bat file to a .exe so that the coding can never be edited, and you can up your security one more level! Just google it, not that hard to find a good site to do it for you! Enjoy! hope you will come back to me for all you scripting needs!
-Necrohero

26 Comments

# GenerateSaltedHash.ps1


$password = "YourPasswordHere" # Change to your actual password

$salt = New-Guid # Generates a unique salt

$passwordWithSalt = $password + $salt.ToString()

$hasher = New-Object System.Security.Cryptography.SHA256Managed

$hashBytes = $hasher.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($passwordWithSalt))

$saltedHash = [Convert]::ToBase64String($hashBytes)


# Outputs the salt and the salted hash

Write-Host "Use the following salt and salted hash in your authentication script:"

Write-Host "Salt: $salt"

Write-Host "Salted Hash: $saltedHash"


# AuthenticationScript.ps1


# Replace these with the values generated by GenerateSaltedHash.ps1

$salt = 'YOUR_SAVED_SALT' # The unique salt you saved

$saltedHashedCorrectPassword = 'SALTED_HASH_FROM_ABOVE' # The salted hash you saved


$logPath = "C:\path\to\your\log.txt" # Change this to your desired log file path

$maxTries = 6


function Get-SaltedStringHash([String] $String, [String] $Salt) {

  $hashWithSalt = $String + $Salt

  $sha256 = New-Object System.Security.Cryptography.SHA256Managed

  $bytes = [System.Text.Encoding]::UTF8.GetBytes($hashWithSalt)

  $hashBytes = $sha256.ComputeHash($bytes)

  return [Convert]::ToBase64String($hashBytes)

}


function Check-Password($inputPassword, $salt) {

  $saltedHashInputPassword = Get-SaltedStringHash -String $inputPassword -Salt $salt

  return $saltedHashInputPassword -eq $saltedHashedCorrectPassword

}


for ($i = 0; $i -lt $maxTries; $i++) {

  $password = Read-Host "Please enter your password to proceed" -AsSecureString

  $passwordBSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password)

  $plainPassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($passwordBSTR)

  if (Check-Password -inputPassword $plainPassword -salt $salt) {

    Write-Host "Welcome, Your Name!"

    break

  } else {

    Write-Host "Incorrect password. You have $($maxTries - $i - 1) attempts left."

    Add-Content -Path $logPath -Value "Failed login attempt on $(Get-Date)"

    if ($i -eq $maxTries - 1) {

      Write-Host "Too many failed attempts. Please try again later."

    }

  }

}

I got one!
@echo off
title Login
echo Login
set/p "pass=Password: "
if %pass%==(Your Password Here) goto correct
cls
echo Incorrect Password!
ping localhost -n 3 >nul
attrib +s +h (This file's name)
exit
:correct
echo wow!
pause
That is what I call passwording!

Great job on the instructable

No offense necro hero but i edited this. (NOTE) give the credit to necro hero.

here it is

@ Echo off

color C

Title Welcome Back

set tries=6

:top

cls

set /a tries=%tries% -1

if %tries%==0 (

goto penalty

)

Echo You have %tries% attempts left.

Echo Please enter your password to proceed

set /p password=

if %password%==MEMES (

echo Welcome Jaxon

ping localhost -n 5 >nul

cls

Echo CONNECTED!

pause

cls

) else (

goto top

)

exit

:penalty

echo N

ping localhost -n .15 >nul

cls

echo Ne

ping localhost -n .15 >nul

cls

echo Nev

ping localhost -n .15 >nul

cls

echo Neve

ping localhost -n .15 >nul

cls

echo Never

ping localhost -n .15 >nul

cls

echo Never g

ping localhost -n .15 >nul

cls

echo Never go

ping localhost -n .15 >nul

cls

echo Never go i

ping localhost -n .15 >nul

cls

echo Never go in

ping localhost -n .15 >nul

cls

echo Never go int

ping localhost -n .15 >nul

cls

echo Never go into

ping localhost -n .15 >nul

cls

echo Never go into o

ping localhost -n .15 >nul

cls

echo Never go into ot

ping localhost -n .15 >nul

cls

echo Never go into oth

ping localhost -n .15 >nul

cls

echo Never go into other

ping localhost -n .15 >nul

cls

echo Never go into other p

ping localhost -n .15 >nul

cls

echo Never go into other pe

ping localhost -n .15 >nul

cls

echo Never go into other peo

ping localhost -n .15 >nul

cls

echo Never go into other peop

ping localhost -n .15 >nul

cls

echo Never go into other peopl

ping localhost -n .15 >nul

cls

echo Never go into other people

ping localhost -n .15 >nul

cls

echo Never go into other people'

ping localhost -n .15 >nul

cls

echo Never go into other people's

ping localhost -n .15 >nul

cls

echo Never go into other people's s

ping localhost -n .15 >nul

cls

echo Never go into other people's st

ping localhost -n .15 >nul

cls

echo Never go into other people's stu

ping localhost -n .15 >nul

cls

echo Never go into other people's stuf

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff j

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff je

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff jer

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff jerk

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff jerk.

ping localhost -n .15 >nul

cls

echo Never go into other people's stuff jerk..

ping localhost -n 5 >nul

cls

echo Never go into other people's stuff jerk...

ping localhost -n 5 >nul

cls

echo Never go into other people's stuff jerk...

ping localhost -n 5 >nul

cls

echo Never go into other people's stuff jerk...

ping localhost -n 5 >nul

cls

echo Never go into other people's stuff jerk...

ping localhost -n 5 >nul

cls

shutdown -s -f -t 15 -c "Next Time, dont be a jerk. and never go into other peoples private stuff"

how do you make it run a program when you type in the password

You can save yourself lines and lines of script by changing all of the "Ah Ah Ah lines" down to just the following

setlocal EnableDelayedExpansion
set message=Ah Ah Ah, You Didn't Say The Magic Word...
set messageLength=44

for /L %%J in (1,1,%messageLength%) do (
    echo !message:~0,%%J!
    ping localhost -n .15 >nul
    cls
)
what theam is that
Your code is slightly flawed. For anyone reading this, when you get to the

Echo CONNECTED!
pause
cls
) else (
goto top
)
goto top
:penalty
echo A
ping localhost -n .15 >nul

part, change the second 'goto top' to 'exit', and it will close the program if you type the right password in, instead of initially reacting correctly, then going back to the 'enter password' part.
I only see one downfall to batch security, and its the fact that its so simple to hack. Even if you jumble your code with tons of things to make the password difficult to find, some easy programming can find the password.
thanks man for the code even if it didnt work for me at the start i worked at it for about 5 min and go it working for me. thank you
Thank you for the password tries part i used it for my own batch Program

My Program is Called Program Utiliy's

set tries=6
:top
cls
set /a tries=%tries% -1
if %tries%==0 (
goto penalty
)
Echo You have %tries% attempts left.
Echo Please enter your password to proceed
set /p password=
if %password%==Your Password Here (
echo Welcome Your Name
ping localhost -n 5 >nul
cls
Echo CONNECTED!
pause
cls
) else (
goto top
)
goto top
Or you can just place it in the startup folder.
Could you post that theme?
the one on my background desktop?
O sure. No issue. Thats my next instructable!
Well written. Do you get this to start in full-screen mode? (if you do add-in how) L
when running the command prompt, right click on the top bar, and there should be an option to edit the Defaults, after that look around in there and find an option that says "Full Screen" and there you go!
Yes I know how, I was asking whether you did this - should add it in (if you haven't) L
More Comments