How to create a Numeric Password Generator in Batch?

What’s happening, guys? I am Binit Ghimire and I am new here in the CoderPradip blog  but I’ve always been a reader of this site since the time it started. I am CoderPradip‘s friend and I’d like to thank him for letting me post in his blog. In this tutorial, I am going to show you how to create a Numeric Password Generator in Batch. This is called Numeric Password Generator in Batch because it is created using Batch Programming (better known as Batch) and it can generate only numeric values. Generally, the extension of programs developed using Batch Programming is .bat. But, they can be converted into executable files using various .BAT to .EXE converters. In this tutorial, we are going to discuss on creating a Numeric Password Generator in Batch.

Things You’ll Need:

  • A Computer,
  • An Operating System installed on your computer, and
  • A Text Editor (Notepad++ 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 be:

@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’ refers to White which is the background and ‘4’ refers to 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:
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:
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.
(Also posted on BinitTech blog)
I will be making more blog posts. So, please stay tuned and see the other posts in the CoderPradip blog.