#!/usr/bin/perl 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 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 $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, #"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 }, ); 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, ); 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 < example. =back =head1 SEE ALSO L, L, L =head1 AKNOWLEDGEMENTS Don Libes of the National Institute of Standards and Technology, who wrote the Expect example, L. =head1 AUTHOR Chris Grau Ecgrau@cpan.orgE =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