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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     1
#!/usr/bin/perl
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
     2
# $Id: pwgen.pl,v 72a196c63f31 2020/12/09 14:24:36 grin $
4
414797051084 pwgen.pl: English source header to be helpful
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     3
#
414797051084 pwgen.pl: English source header to be helpful
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     4
# (c)Peter Gervai, 2002-2020; Released under GPLv3+ + CC_BY-SA-4.0
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
     5
#
4
414797051084 pwgen.pl: English source header to be helpful
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     6
# Password generator, 2002/04/08; 2016/11/09; 2020/12/09
414797051084 pwgen.pl: English source header to be helpful
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     7
#
414797051084 pwgen.pl: English source header to be helpful
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     8
# This code generates easy (easier) to spell and remember passwords.
414797051084 pwgen.pl: English source header to be helpful
Peter Gervai <grin@grin.hu>
parents: 3
diff changeset
     9
# The length, in-dashes and plenty of stuff are configurable.
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    10
#
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    11
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    12
use Getopt::Long;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    13
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    14
my $help;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    15
my $words=5;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    16
my $syllab=4;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    17
my $dash;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    18
my $dashlen=2;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    19
my $dashchr='-';
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    20
my $longsyl=20;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    21
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    22
GetOptions(
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    23
  "help" 	=> \&help,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    24
  "words=i" 	=> \$words,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    25
  "syllab=i"	=> \$syllab,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    26
  "dash"	=> \$dash,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    27
  "dashlen=i"	=> \$dashlen,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    28
  "longsyl=i"	=> \$longsyl,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    29
  "dashchr=s"	=> \$dashchr,
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    30
) or &help;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    31
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    32
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    33
$vowel='aeiou';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    34
#$cons='bcdfghjklmnpqrstvwxyz';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    35
 $cons='bcdfghjklmnprstvxyz';
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    36
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    37
$vlen=length($vowel);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    38
$clen=length($cons);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    39
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    40
$longsyl=20; # percent
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    41
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    42
for (1..$words) {
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    43
    my $dash_count=0;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    44
    my $sylnum=$syllab + rand(3);
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    45
    for my $i (1..$sylnum) {
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    46
        print substr($cons,rand($clen),1);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    47
        print substr($vowel,rand($vlen),1);
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    48
        print substr($cons,rand($clen),1) if $longsyl > rand(100);
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    49
        print $dashchr  unless !$dash or ++$dash_count % $dashlen  or  $i>$sylnum-$dashlen;
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    50
    }
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    51
    print "   ";
0
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    52
}
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    53
624a9ab34425 Add code lying around to the repo
Peter Gervai <grin@grin.hu>
parents:
diff changeset
    54
print "\n";
3
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    55
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    56
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    57
sub help {
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    58
    print "Usage:\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    59
    print "  $0 [--help] [--words=$words] [--syllab=$syllab] [--longsyl=$longsyl] [--dash [--dashchr=$dashchr] [--dashlen=$dashlen]]\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    60
    print "      words:   how many passwords to display\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    61
    print "      syllab:  how many syllables in a word\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    62
    print "      dash:    use dash between syllables\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    63
    print "      dashlen: use dash between every N syllable\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    64
    print "      longsyl: long syllable probability (percent)\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    65
    print "      dashchr: character to use instead of '-'\n";
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    66
    exit;
d4bb4405d439 pwgen.pl: Implement proper getopt, and install various knobs and wheels to
Peter Gervai <grin@grin.hu>
parents: 0
diff changeset
    67
}