Things You'll Need:
A Computer, An Operating System installed on your computer & A Text Editor (Notepad++ is recommended.)Steps:
1. Open any text editor that you've. If you have Notepad++, open it.To make it easy, click on 'Language' option at the top of Notepad++ and select 'Batch'.
2. Then, type the initial codes of Batch Programming as given below:
@echo off
title BINIT's PASSWORD GENERATOR
color f4
Here,
In the first line, '@' is used to hide the echo of the batch command, 'echo' is used to output (show/display) status text to the screen and 'off' is used to turn off command echoing.
In the second line, 'title' is used to define the title of the program as shown in the following screenshot:
In the third line, 'color' is used to define the color of the background & foreground (text) of the program. Here, the color is 'f4' where f is white which is the background and 4 is red which is the foreground. You can know the color codes used in batch by searching on various search engines.
3. After those codes, press Enter and type the following codes:
:MENU
cls
echo __________________________________________
echo BINIT's PASSWORD GENERATOR
echo https://thebinitghimire.blogspot.com
echo __________________________________________
echo MAIN MENU
echo __________________________________________
echo 1) GENERATE PASSWORD (PRESS 1)
echo 2) EXIT (PRESS 2)
set input=
set /p input= WHAT DO YOU WANT TO CHOOSE?:
if %input%==1 goto GP
if %input%==2 EXIT
pause
Here, :MENU is used to define the variable 'MENU'. It defines the main menu in this program 'cls' is used to clear the screen. 'echo' is used to print the text on the screen. It is used to define the contents of the program. 'set input' is used to accept input from the user. 'set /p' is used to accept single character input from the user. If the user's input is 1, it goes to the variable GP (it will be used after sometime in the program.). This means the password is generated. If the user's input is 2, the program exits.
The text above the last line in this image are the result of 'echo'. |
4. After the above codes, press Enter and then press Enter again to leave 1 line blank. Then, type the following codes:
:GP
cls
echo __________________________________________
echo BINIT's PASSWORD GENERATOR
echo https://thebinitghimire.blogspot.com
echo __________________________________________
echo PASSWORD GENERATING MENU
echo __________________________________________
echo GENERATED PASSWORD: %RANDOM%
echo __________________________________________
echo Remember to write/copy the password!
echo THANKS FOR USING MY PASSWORD GENERATOR!
echo __________________________________________
echo 1) GENERATE ANOTHER PASSWORD (PRESS 1)
echo 2) GO BACK TO MAIN MENU (PRESS 2)
echo 3) EXIT (PRESS 3)
set input=
set /p input= WHAT DO YOU WANT TO CHOOSE?:
if %input%==1 goto GP
if %input%==2 goto MENU
if %input%==3 EXIT
Here, the variable GP is defined. When the input of the user is 1 in the previous step, it goes to the variable GP & generates the numeric password. The program is divided into main program and sub-program to make the program easier to understand & to reduce the errors. The variable GP defines the sub-program. If the user's input was 1 in Step 3, the program will look similar to the following screenshot:
'cls' is used to clear the screen. 'echo' is used to print the text on the screen. '%RANDOM%' is used to generate random numbers which is considered as password in this program. 'set input' is used to accept input from the user. 'set /p' is used to take a single character input from the user.
Here, If the user's input is 1, another password is generated because, it again goes to GP. If the user's input is 2, it goes back to the main menu because, in the program code, it goes to the variable MENU which defines the Main Menu. If the user's input is 3, the program exits.
5. After you type all the above codes, save the program with '.bat' extension. For example, save it as 'Password Generator.bat'. Otherwise, the program won't run. After saving the program, open the saved file having '.bat' extension & the program will run. Try entering values!
At last, your program code should look like this:
In this program,
1. The title of the program can be modified with your own title.
2. The color code 'f4' can be replaced by other color codes. You must use the color codes of Batch. HTML color codes won't work. You can know the color codes used in batch by searching on various search engines.
3. You can make the length of the password longer by adding a hyphen '-' or just by giving space and typing %RANDOM% again. You can do this many times as you want.
The limitation of this program is that it can generate only numeric text not alphabetic text or special characters. A new tutorial on generating random alphanumeric characters (if possible, special characters, too.) in batch will be published soon.
0 comments:
Post a Comment
Write Your Comments!