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 |
0 | 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 | 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 | 10 |
# |
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 | 32 |
|
33 |
$vowel='aeiou'; |
|
34 |
#$cons='bcdfghjklmnpqrstvwxyz'; |
|
35 |
$cons='bcdfghjklmnprstvxyz'; |
|
36 |
||
37 |
$vlen=length($vowel); |
|
38 |
$clen=length($cons); |
|
39 |
||
40 |
$longsyl=20; # percent |
|
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 | 45 |
for my $i (1..$sylnum) { |
46 |
print substr($cons,rand($clen),1); |
|
47 |
print substr($vowel,rand($vlen),1); |
|
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 | 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 | 52 |
} |
53 |
||
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 |
} |