2012-09-04 13:32:24 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
2016-05-22 22:27:43 +00:00
|
|
|
=encoding utf8
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
goodpasswd - generate good access codes
|
|
|
|
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
B<goodpasswd>
|
|
|
|
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
B<goodpasswd> generates access codes that:
|
|
|
|
|
|
|
|
=over 3
|
|
|
|
|
|
|
|
=item Z<>* are hard to guess
|
|
|
|
|
|
|
|
=item Z<>* will be displayed unambigously in any (normal) font
|
|
|
|
|
|
|
|
=item Z<>* will survive being passed through a bad fax machine
|
|
|
|
|
|
|
|
=item Z<>* will survive being passed through handwriting
|
|
|
|
|
|
|
|
=item Z<>* will survive unquoted in most scripts
|
|
|
|
|
|
|
|
=item Z<>* has characters from the character classes UPPER lower number and sign
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head2 Characters considered too close
|
|
|
|
|
|
|
|
These character couples are too similar either in different fonts or
|
|
|
|
in a bad copy and are thus forbidden: B8 cC g9 6G kK lI l1 oO O0 pP sS uU vV xX zZ Z2 ,. :; `' S5
|
|
|
|
|
|
|
|
These characters cause problems in URLs: @/:
|
|
|
|
|
|
|
|
These characters cause problems in shell: ! " # $ & ( ) [ ] { } ? | < > \ * =
|
|
|
|
|
|
|
|
These characters cause problems in SQL (wildcard): %
|
|
|
|
|
|
|
|
These characters are hard to type: ^ ~ ¨ ¤ § ½ æ ø å Æ Ø Å
|
|
|
|
|
|
|
|
=head2 Other restrictions
|
|
|
|
|
|
|
|
Never use the same chars twice in a row: e.g. -- is bad.
|
|
|
|
|
|
|
|
Do not start with '-' or '+' as that looks like an (long) option
|
|
|
|
|
|
|
|
=head1 EXAMPLE
|
|
|
|
|
|
|
|
B<goodpasswd> will give output similar to FJiY7j+7DQ-D.
|
|
|
|
|
|
|
|
=cut
|
|
|
|
|
2014-04-26 09:02:32 +00:00
|
|
|
#
|
|
|
|
# US-kbd: ~!@#$%^&*()_+ [] {} ;'\ :"| < > ,./ <>?
|
|
|
|
# DK-kbd: §!"#¤%&/()=?` å" Å^ æø' ÆØ* < > ,.- ;:_
|
|
|
|
# Common: ! # % < > ,.
|
2012-09-04 13:32:24 +00:00
|
|
|
|
|
|
|
my $pw;
|
2014-09-18 12:15:00 +00:00
|
|
|
my @chars=split //, 'abdefhijmnqrtyADEFHJLMNQRTY347+-';
|
2012-09-04 13:32:24 +00:00
|
|
|
do {
|
|
|
|
$pw = "";
|
|
|
|
for (1..12) {
|
2014-09-18 12:15:00 +00:00
|
|
|
$pw .= $chars[rand $#chars+1]
|
2012-09-04 13:32:24 +00:00
|
|
|
}
|
2014-09-18 12:15:00 +00:00
|
|
|
} while (($pw =~ /^[+-]/ or $pw =~ /(.)\1/) or
|
|
|
|
not($pw =~ /[A-Z]/ and
|
2012-09-04 13:32:24 +00:00
|
|
|
$pw =~ /[a-z]/ and
|
|
|
|
$pw =~ /[0-9]/ and
|
|
|
|
$pw =~ /[^a-zA-Z0-9]/));
|
|
|
|
|
|
|
|
print "$pw\n";
|