tangetools/goodpasswd/goodpasswd
2024-08-17 22:54:26 +02:00

81 lines
1.7 KiB
Perl
Executable file

#!/usr/bin/perl
=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 G6 kK lI l1 oO O0 pP sS S5 uU vV xX zZ Z2 ,. :; `'
These characters cause problems in URLs: @/:
These characters cause problems in shell: ! " # $ & ( ) [ ] { } ? | < > \ * =
These characters cause problems in SQL: % (wildcard) + (login)
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 '-' as that looks like an (long) option
=head1 EXAMPLE
B<goodpasswd> will give output similar to iTtNRf3MYdMb+rNhYniY.
=cut
# US-kbd: ~!@#$%^&*()_+ [] {} ;'\ :"| < > ,./ <>?
# DK-kbd: §!"#¤%&/()=?` å" Å^ æø' ÆØ* < > ,.- ;:_
# Common: ! # % < > ,.
my $pw;
# 31-1 possibilities = ~4.9 bit entropy
# 20 chars = 98 bit
my @chars=split //, 'abdefhijmnqrtyADEFHJLMNQRTY347-';
do {
$pw = "";
for (1..20) {
$pw .= $chars[rand $#chars+1]
}
} while (($pw =~ /^[+-]/ or $pw =~ /(.)\1/) or
not($pw =~ /[A-Z]/ and
$pw =~ /[a-z]/ and
$pw =~ /[0-9]/ and
$pw =~ /[^a-zA-Z0-9]/));
print "$pw\n";