Quick Random Password Generator for Perl

Quick Random Password Generator for Perl

Mostly writing this for my own future benefit, but if this can help someone else in the process, perfect.

Basically, create random strings of random sizes using random characters until the size of the resulting string is greater than 16. Pretty simple.

#!/usr/bin/perl

my @alphanumeric = ('a'..'z', 'A'..'Z', 0..9,'!','_','-');
my @numeric = (0..9);
my $randpassword = '';

until ( length($randpassword) > 16 ) {
        $randpassword = $randpassword . join '', map $alphanumeric[rand @alphanumeric], 0..(rand @numeric);
}

print "$randpassword\n"

Save the resulting file as “randpasswd.pl” on a Linux system (I used Ubuntu), set as executable, and run it in a command line to generate a random password.

One thought on “Quick Random Password Generator for Perl

Leave a Reply

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

10 + eighteen =