pwgen.pl
author Peter Gervai <grin@grin.hu>
Wed, 09 Dec 2020 15:46:30 +0100
changeset 4 414797051084
parent 3 d4bb4405d439
child 5 98bc7c6e581a
permissions -rwxr-xr-x
pwgen.pl: English source header to be helpful

#!/usr/bin/perl
# $Id: pwgen.pl,v 72a196c63f31 2020/12/09 14:24:36 grin $
#
# (c)Peter Gervai, 2002-2020; Released under GPLv3+ + CC_BY-SA-4.0
#
# Password generator, 2002/04/08; 2016/11/09; 2020/12/09
#
# This code generates easy (easier) to spell and remember passwords.
# The length, in-dashes and plenty of stuff are configurable.
#

use Getopt::Long;

my $help;
my $words=5;
my $syllab=4;
my $dash;
my $dashlen=2;
my $dashchr='-';
my $longsyl=20;

GetOptions(
  "help" 	=> \&help,
  "words=i" 	=> \$words,
  "syllab=i"	=> \$syllab,
  "dash"	=> \$dash,
  "dashlen=i"	=> \$dashlen,
  "longsyl=i"	=> \$longsyl,
  "dashchr=s"	=> \$dashchr,
) or &help;


$vowel='aeiou';
#$cons='bcdfghjklmnpqrstvwxyz';
 $cons='bcdfghjklmnprstvxyz';

$vlen=length($vowel);
$clen=length($cons);

$longsyl=20; # percent

for (1..$words) {
    my $dash_count=0;
    my $sylnum=$syllab + rand(3);
    for my $i (1..$sylnum) {
        print substr($cons,rand($clen),1);
        print substr($vowel,rand($vlen),1);
        print substr($cons,rand($clen),1) if $longsyl > rand(100);
        print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
    }
    print "   ";
}

print "\n";


sub help {
    print "Usage:\n";
    print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
    print "      words:   how many passwords to display\n";
    print "      syllab:  how many syllables in a word\n";
    print "      dash:    use dash between syllables\n";
    print "      dashlen: use dash between every N syllable\n";
    print "      longsyl: long syllable probability (percent)\n";
    print "      dashchr: character to use instead of '-'\n";
    exit;
}