How to generate random password using perl

Last updated on August 7th, 2022 at 07:07 pm

Tutorial on how to create random password using perl script. We are using rand() function available in perl.  Take a look at the script below.

#!/usr/local/bin/perl -W
print "Content-type: text/html \n\n";
print "<title>Random Password Generator Using Mistonline.in Tutorial</title>";
my $pwd;
my @my_char_list = (('A'..'Z'), ('a'..'z'), ('!','@','%','^'), (0..9));
my $range_dis = $#my_char_list + 1;
for (1..17) {
   $pwd .= $my_char_list[int(rand($range_dis))];
}
print "<b>Random Password Generated Is</b>: $pwd\n";

NOTE:- Make sure you modify the perl install location in the script header

Since I don’t have a Perl environment setup I am going to show you the output of the above script by executing it directly

[email protected]:~# ./random_password.pl
Content-type: text/html

<title>Random Password Generator Using Mistonline.in Tutorial</title><b>Random Password Generated Is</b>: [email protected]^kHYO
[email protected]:~# ./random_password.pl
Content-type: text/html

<title>Random Password Generator Using Mistonline.in Tutorial</title><b>Random Password Generated Is</b>: E88WP5uSsgtf5a5DI
[email protected]:~# ./random_password.pl
Content-type: text/html

<title>Random Password Generator Using Mistonline.in Tutorial</title><b>Random Password Generated Is</b>: 8QTH7B5rPO1ubmpv3

As you can see it generated random unique password in each execution

Click to rate this tutorial!
[Total: 6 Average: 4]

Leave a Reply

Your email address will not be published. Required fields are marked *