Create a simple password screen using only Notepad.
Note: This tutorial will only work on Windows.
Today you’re going to create a batch script that asks the user for an input and assigns that input to a variable. It then uses an if/else statement to determine if the password is correct.
First open Notepad.exe. If the text is massive, then click on ‘Format’ > ‘Font’ and change the size to 16. Now you can start coding. Type the following code in paying attention to the syntax and even how many spaces there are in between the text:
@echo off title Log In set /P pass=Enter Password:
@echo off just stops the command line from printing out (showing on the screen) every single thing it does.
title Log In sets the window’s title to ‘Log in’.
set /P pass=Enter Password: asks for user input and sets a variable called ‘pass’ to the input. ‘Enter Password:’ is what it asks the user.
IF "%pass%"=="Micropi" ( echo Correct! ) ELSE ( echo Incorrect Password ) pause
The IF statement then asks whether the variable ‘pass’ has the value of ‘Micropi'(which is the password). If it is, it prints (or echos) out ‘Correct!.
If it isn’t is prints ‘Incorrect Password’. The program then pauses, and waits for the user before closing. The code all together:
@echo off title Log In set /P pass=Enter Password: IF "%pass%"=="Micropi" ( echo Correct! ) ELSE ( echo Incorrect Password ) pause
Now click on ‘File’ > ‘Save as’ and change ‘Text Documents (*.txt)’ to ‘All files’. Then name your file ‘LogIn.bat’. The .bat is important as this is what saves it as a batch file not a text document. Click on ‘Save’. Now open File Explorer and double click your batch file. The batch file should run. Don’t forget that the password is ‘Micropi’ (case sensitive)!