/usr/bin/mkpasswd.pl is in libstring-mkpasswd-perl 0.05-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | #!/usr/bin/perl
eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
if 0; # not running under some shell
use 5.006001;
use strict;
use File::Basename qw(basename);
use Getopt::Long qw(GetOptions);
use String::MkPasswd qw(mkpasswd);
use Text::Wrap qw(wrap);
# Defaults.
use constant LENGTH => 9;
use constant MINNUM => 2;
use constant MINLOWER => 2;
use constant MINUPPER => 2;
use constant MINSPECIAL => 1;
use constant DISTRIBUTE => "";
use constant NOAMBIGUOUS => 0;
#use constant VERBOSE => "";
#use constant PASSWD => "/bin/passwd";
# Configuration.
my $length = LENGTH;
my $minnum = MINNUM;
my $minlower = MINLOWER;
my $minupper = MINUPPER;
my $minspecial = MINSPECIAL;
my $distribute = DISTRIBUTE;
my $noambiguous = NOAMBIGUOUS;
#my $verbose = VERBOSE;
#my $passwd = PASSWD;
my $help = "";
Getopt::Long::Configure("bundling");
my $getopt = GetOptions(
"length|l=i" => \$length,
"digits|d=i" => \$minnum,
"lower|c=i" => \$minlower,
"upper|C=i" => \$minupper,
"special|s=i" => \$minspecial,
"distribute|2" => \$distribute,
"noambiguous|n" => \$noambiguous,
#"verbose|v" => \$verbose,
#"passwd|p" => \$passwd,
"help|h" => \$help,
# Getopt::Long doesn't support combining '--no' with options that take
# arguments, so this is just my way of faking it.
"nodigits|no-digits" => sub { $minnum = 0 },
"nolower|no-lower" => sub { $minlower = 0 },
"noupper|no-upper" => sub { $minupper = 0 },
"nospecial|no-special" => sub { $minspecial = 0 },
"noambiguous|no-ambiguous|no-lookalike|nolookalike" => sub { $noambiguous = 1 },
);
if ( $help ) {
&usage();
exit 0;
}
if ( !$getopt ) {
&usage();
exit 1;
}
my $pass = mkpasswd(
-length => $length,
-minnum => $minnum,
-minlower => $minlower,
-minupper => $minupper,
-minspecial => $minspecial,
-distribute => $distribute,
-noambiguous => $noambiguous,
);
if ( !$pass ) {
$Text::Wrap::columns = 72;
print STDERR wrap("", "",
"Impossible to generate $length-character password with $minnum "
. "numbers, $minlower lowercase letters, $minupper uppercase letters "
. "and $minspecial special characters.\n"
);
exit 1;
}
print "$pass\n";
exit 0;
sub usage {
print <<EOF;
Usage: @{[ basename $0 ]} [-options]
-l # | --length=# length of password (default = @{[ LENGTH ]})
-d # | --digits=# min # of digits (default = @{[ MINNUM ]})
-c # | --lower=# min # of lowercase chars (default = @{[ MINLOWER ]})
-C # | --upper=# min # of uppercase chars (default = @{[ MINUPPER ]})
-s # | --special=# min # of special chars (default = @{[ MINSPECIAL ]})
-2 | --distribute alternate hands
-n | --noambiguous don't include chars that might be mistaken for others
--nodigits alias for --digits=0
--nolower alias for --lower=0
--noupper alias for --upper=0
--nospecial alias for --special=0
--nolookalike alias for --noambiguous
EOF
}
__END__
=head1 NAME
mkpasswd.pl - example to generate new password with String::MkPasswd
=head1 SYNOPSIS
mkpasswd.pl [-options]
#!/bin/sh
NEW_PASSWD=`mkpasswd.pl`
=head1 DESCRIPTION
This program generates a random password, allowing for some tuning of
character distribution. The password is sent to standard output.
=head2 OPTIONS
=over 4
=item -l # | --length=#
The total length of the password. The default is 9.
=item -d # | --digits=#
The minimum number of digits that will appear in the final password.
The default is 2.
=item -c # | --lower=#
The minimum number of lower-case characters that will appear in the
final password. The default is 2.
=item -C # | --upper=#
The minimum number of upper-case characters that will appear in the
final password. The default is 2.
=item -s # | --special=#
The minimum number of non-alphanumeric characters that will appear in
the final password. The default is 1.
=item -2 | --distribute
If specified, password characters will be distributed between the left-
and right-hand sides of the keyboard. This makes it more difficult for
an onlooker to see the password as it is typed.
=item --nodigits | --no-digits
Alias for --digits=0.
=item --nolower | --no-lower
Alias for --lower=0.
=item --noupper | --no-upper
Alias for --upper=0.
=item --nospecial | --no-special
Alias for --special=0.
=back
=head1 BUGS
=over 4
=item *
While not really a bug, the .pl extension has been added to avoid
conflict with the program of the same name distributed with Expect.
=back
=head1 TODO
=over 4
=item *
For completeness, add user password setting functionality as found in
Expect's L<mkpasswd(1)> example.
=back
=head1 SEE ALSO
L<http://expect.nist.gov/#examples>,
L<mkpasswd(1)>,
L<String::MkPasswd>
=head1 AKNOWLEDGEMENTS
Don Libes of the National Institute of Standards and Technology, who
wrote the Expect example, L<mkpasswd(1)>.
=head1 AUTHOR
Chris Grau E<lt>cgrau@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2003-2004 by Chris Grau
This library is free software; you can redistribute it and/or modify it
under the same terms as Perl itself, either Perl version 5.8.1 or, at
your option, any later version of Perl 5 you may have available.
=cut
|