Skip to content

Instantly share code, notes, and snippets.

@Decstasy
Created August 20, 2021 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Decstasy/c080765410f5fb4f6375d7792f12c18c to your computer and use it in GitHub Desktop.
Save Decstasy/c080765410f5fb4f6375d7792f12c18c to your computer and use it in GitHub Desktop.
#!/usr/bin/perl -W
# Dennis Ullrich
### Password settings:
# Output settings:
$x = 4; # Passwords per line
$y = 25; # Lines
# (quantity,(charset))
@lower = (6,('a'..'x'));
@upper = (6,('A'..'X'));
@numbers = (5,(0..9));
@special = (3,('!','$','.','-','+'));
### MAIN
use List::Util qw(shuffle);
use Getopt::Long;
GetOptions(
'single!' => \$single,
'no-newline!' => \$no_newline,
) or die "Incorrect usage!\n";
if ($single){
$no_newline ? print &pwgen : print &pwgen."\n";
exit(0);
}
for (1..$y){
my $line;
for (1..$x){
$line .= &pwgen." ";
}
print $line."\n";
}
sub random{
my $chars = shift(@_);
my $string;
my $range = $#_ + 1;
for (1..$chars){
$string .= $_[int(rand($range))];
}
return $string;
}
sub pwgen{
my $pw = &random(@lower);
$pw .= &random(@upper);
$pw .= &random(@special);
$pw .= &random(@numbers);
my @pw = split //, $pw;
return join '', shuffle(@pw[0..$#pw]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment