Random Password in Perl

Here’s a script I keep in ~/bin/randpwd.pl and use frequently to generate random password strings. It prints an 8 character password by default, but you can also specify a different password length on the command line. I left out the capital letter “o” to avoid confusion with the number zero. ;-)

#!/usr/bin/perl -w

# /usr/local/bin/randpwd.pl {length}
# Generate a random password.
# by Jean-Sebastien Morisset (https://surniaulula.com/)

use strict;

my @chrs = ( 'A'..'N', 'P'..'Z', 'a'..'z', 0..9 );
my $len = defined( $ARGV[0] ) ? int( $ARGV[0] ) : 8;
print $chrs[rand @chrs] for 1 .. $len;
print "\n";

exit 0;
Find this content useful? Share it with your friends!