r17497 - in /branches/upstream/libstring-mkpasswd-perl: ./ current/ current/bin/ current/lib/ current/lib/String/ current/t/

gregoa-guest at users.alioth.debian.org gregoa-guest at users.alioth.debian.org
Sun Mar 16 00:43:05 UTC 2008


Author: gregoa-guest
Date: Sun Mar 16 00:43:04 2008
New Revision: 17497

URL: http://svn.debian.org/wsvn/?sc=1&rev=17497
Log:
[svn-inject] Installing original source of libstring-mkpasswd-perl

Added:
    branches/upstream/libstring-mkpasswd-perl/
    branches/upstream/libstring-mkpasswd-perl/current/
    branches/upstream/libstring-mkpasswd-perl/current/Changes
    branches/upstream/libstring-mkpasswd-perl/current/MANIFEST
    branches/upstream/libstring-mkpasswd-perl/current/MANIFEST.SKIP
    branches/upstream/libstring-mkpasswd-perl/current/META.yml
    branches/upstream/libstring-mkpasswd-perl/current/Makefile.PL
    branches/upstream/libstring-mkpasswd-perl/current/README
    branches/upstream/libstring-mkpasswd-perl/current/bin/
    branches/upstream/libstring-mkpasswd-perl/current/bin/mkpasswd.pl   (with props)
    branches/upstream/libstring-mkpasswd-perl/current/lib/
    branches/upstream/libstring-mkpasswd-perl/current/lib/String/
    branches/upstream/libstring-mkpasswd-perl/current/lib/String/MkPasswd.pm
    branches/upstream/libstring-mkpasswd-perl/current/perl-String-MkPasswd.spec
    branches/upstream/libstring-mkpasswd-perl/current/t/
    branches/upstream/libstring-mkpasswd-perl/current/t/01use.t
    branches/upstream/libstring-mkpasswd-perl/current/t/02length.t
    branches/upstream/libstring-mkpasswd-perl/current/t/03count.t
    branches/upstream/libstring-mkpasswd-perl/current/t/04fatal.t

Added: branches/upstream/libstring-mkpasswd-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/Changes?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/Changes (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/Changes Sun Mar 16 00:43:04 2008
@@ -1,0 +1,14 @@
+Revision history for Perl extension String::MkPasswd.
+
+0.02  Wed Mar 17 08:17:10 PST 2004
+	- Applied changes from Adrian Gee <adrian.gee at anu.edu.au> allowing -minnum,
+	  -minlower, -minupper and -minspecial to be zero in the call to
+	  mkpasswd().
+	- Fixed mkpasswd.pl so it actually works.  It was passing the wrong key
+	  names to mkpasswd(), so the defaults were always used.
+	- Added --no{num,lower,upper,special} options to mkpasswd.pl as
+	  alternatives to --min{num,lower,upper,special}=0.
+
+0.01  Wed Nov 12 17:29:08 2003
+	- original version; created by h2xs 1.23 with options
+		--compat-version=5.6.1 --omit-autoload --omit-XS --name=String::MkPasswd --use-new-tests

Added: branches/upstream/libstring-mkpasswd-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/MANIFEST?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/MANIFEST (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/MANIFEST Sun Mar 16 00:43:04 2008
@@ -1,0 +1,13 @@
+Changes
+Makefile.PL
+MANIFEST
+MANIFEST.SKIP
+README
+bin/mkpasswd.pl
+lib/String/MkPasswd.pm
+perl-String-MkPasswd.spec
+t/01use.t
+t/02length.t
+t/03count.t
+t/04fatal.t
+META.yml                                 Module meta-data (added by MakeMaker)

Added: branches/upstream/libstring-mkpasswd-perl/current/MANIFEST.SKIP
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/MANIFEST.SKIP?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/MANIFEST.SKIP (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/MANIFEST.SKIP Sun Mar 16 00:43:04 2008
@@ -1,0 +1,27 @@
+^blib/
+Makefile$
+Makefile\.[a-z]+$
+^pm_to_blib$
+CVS/.*
+,v$
+^tmp/
+\.old$
+\.bak$
+~$
+^#
+\.shar$
+\.tar$
+\.tgz$
+\.tar\.gz$
+\.zip$
+_uu$
+\.swp$
+/old/
+
+^local/
+test\.pl$
+temp\.pl$
+
+.cvsignore$
+removed-t/
+old/

Added: branches/upstream/libstring-mkpasswd-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/META.yml?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/META.yml (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/META.yml Sun Mar 16 00:43:04 2008
@@ -1,0 +1,14 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         String-MkPasswd
+version:      0.02
+version_from: lib/String/MkPasswd.pm
+installdirs:  site
+requires:
+    File::Basename:                0
+    Getopt::Long:                  0
+    Test::More:                    0
+    Text::Wrap:                    0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17

Added: branches/upstream/libstring-mkpasswd-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/Makefile.PL?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/Makefile.PL (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/Makefile.PL Sun Mar 16 00:43:04 2008
@@ -1,0 +1,21 @@
+use 5.006001;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+	NAME			=> "String::MkPasswd",
+	VERSION_FROM	=> "lib/String/MkPasswd.pm",
+	PREREQ_PM		=> {
+		"File::Basename"	=>  0,
+		"Getopt::Long"		=>  0,
+		"Test::More"		=>  0,
+		"Text::Wrap"		=>  0,
+	},
+	EXE_FILES		=> [ "bin/mkpasswd.pl" ],
+	($] >= 5.005
+		? (
+			ABSTRACT_FROM	=> "lib/String/MkPasswd.pm",
+			AUTHOR			=> "Chris Grau <cgrau\@cpan.org>",
+		)
+		: ()
+	),
+);

Added: branches/upstream/libstring-mkpasswd-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/README?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/README (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/README Sun Mar 16 00:43:04 2008
@@ -1,0 +1,43 @@
+String-MkPasswd version 0.02
+============================
+
+This Perl library defines a single function, mkpasswd(), to generate
+random passwords.  The function is meant to be a simple way for
+developers and system administrators to easily generate a relatively
+secure password.
+
+Also included in this distribution is the example program
+mkpasswd.pl(3pm) and a .spec file for RPM builders.
+
+INSTALLATION
+
+To install this module type the following:
+
+   perl Makefile.PL
+   make
+   make test
+   make install
+
+DEPENDENCIES
+
+This module requires these other modules and libraries:
+
+  File::Basename
+  Getopt::Long
+  Test::More
+  Text::Wrap
+
+All of these are included with recent versions of Perl.
+
+COPYRIGHT AND LICENCE
+
+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.
+
+AKNOWLEDGEMENTS
+
+Don Libes of the National Institute of Standards and Technology, who
+wrote the Expect example, L<mkpasswd(1)>.

Added: branches/upstream/libstring-mkpasswd-perl/current/bin/mkpasswd.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/bin/mkpasswd.pl?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/bin/mkpasswd.pl (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/bin/mkpasswd.pl Sun Mar 16 00:43:04 2008
@@ -1,0 +1,215 @@
+#!/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 <<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
+	--nodigits          alias for --digits=0
+	--nolower           alias for --lower=0
+	--noupper           alias for --upper=0
+	--nospecial         alias for --upper=0
+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 at 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

Propchange: branches/upstream/libstring-mkpasswd-perl/current/bin/mkpasswd.pl
------------------------------------------------------------------------------
    svn:executable = 

Added: branches/upstream/libstring-mkpasswd-perl/current/lib/String/MkPasswd.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/lib/String/MkPasswd.pm?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/lib/String/MkPasswd.pm (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/lib/String/MkPasswd.pm Sun Mar 16 00:43:04 2008
@@ -1,0 +1,311 @@
+package String::MkPasswd;
+
+use 5.006001;
+use strict;
+use base qw(Exporter);
+
+use Carp qw(croak);
+
+# 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 FATAL		=> "";
+
+our %EXPORT_TAGS = (
+	all	=> [ qw(mkpasswd) ],
+);
+our @EXPORT_OK = @{ $EXPORT_TAGS{all} };
+our $VERSION = "0.02";
+our $FATAL = "";
+
+my %keys = (
+	dist	=> {
+		lkeys	=> [ qw(q w e r t a s d f g z x c v b) ],
+		rkeys	=> [ qw(y u i o p h j k l n m) ],
+		lnums	=> [ qw(1 2 3 4 5 6) ],
+		rnums	=> [ qw(7 8 9 0) ],
+		lspec	=> [ qw(! @ $ %), "#" ],
+		rspec	=> [
+			qw(^ & * ( ) - = _ + [ ] { } \ | ; : ' " < > . ? /), ","
+		],
+	},
+
+	undist	=> {
+		lkeys	=> [
+			qw(a b c d e f g h i j k l m n o p q r s t u v w x y z)
+		],
+		rkeys	=> [
+			qw(a b c d e f g h i j k l m n o p q r s t u v w x y z)
+		],
+		lnums	=> [ qw(0 1 2 3 4 5 6 7 8 9) ],
+		rnums	=> [ qw(0 1 2 3 4 5 6 7 8 9) ],
+		lspec	=> [
+			qw(! @ $ % ~ ^ & * ( ) - = _ + [ ] { } \ | ; : ' " < > . ? /),
+			"#", ","
+		],
+		rspec	=> [
+			qw(! @ $ % ~ ^ & * ( ) - = _ + [ ] { } \ | ; : ' " < > . ? /),
+			"#", ","
+		],
+	},
+);
+
+sub mkpasswd {
+	my $class	= shift if UNIVERSAL::isa $_[0], __PACKAGE__;
+	my %args	= @_;
+
+	# Configuration.
+	my $length		= $args{"-length"}     || LENGTH;
+	my $minnum		= defined $args{"-minnum"}
+		? $args{"-minnum"}
+		: MINNUM;
+	my $minlower	= defined $args{"-minlower"}
+		? $args{"-minlower"}
+		: MINLOWER;
+	my $minupper	= defined $args{"-minupper"}
+		? $args{"-minupper"}
+		: MINUPPER;
+	my $minspecial	= defined $args{"-minspecial"}
+		? $args{"-minspecial"}
+		: MINSPECIAL;
+	my $distribute	= defined $args{"-distribute"}
+		? $args{"-distribute"}
+		: DISTRIBUTE;
+	my $fatal		= defined $args{"-fatal"}
+		? $args{"-fatal"}
+		: FATAL;
+
+	if ( $minnum + $minlower + $minupper + $minspecial > $length ) {
+		if ( $fatal || $FATAL ) {
+			croak "Impossible to generate $length-character password with "
+					. "$minnum numbers, $minlower lowercase letters, "
+					. "$minupper uppercase letters and $minspecial special "
+					. "characters";
+		} else {
+			return;
+		}
+	}
+
+	# If there is any underspecification, use additional lowercase letters.
+	$minlower = $length - ($minnum + $minupper + $minspecial);
+
+	# Choose left or right starting hand.
+	my $initially_left = my $isleft = int rand 2;
+
+	# Select distribution of keys.
+	my $lkeys = $distribute ? $keys{dist}{lkeys} : $keys{undist}{lkeys};
+	my $rkeys = $distribute ? $keys{dist}{rkeys} : $keys{undist}{rkeys};
+	my $lnums = $distribute ? $keys{dist}{lnums} : $keys{undist}{lnums};
+	my $rnums = $distribute ? $keys{dist}{rnums} : $keys{undist}{rnums};
+	my $lspec = $distribute ? $keys{dist}{lspec} : $keys{undist}{lspec};
+	my $rspec = $distribute ? $keys{dist}{rspec} : $keys{undist}{rspec};
+
+	# Generate password.
+
+	my @lpass = (undef) x $length;	# password chars typed by left hand
+	my @rpass = (undef) x $length;	# password chars typed by right hand
+	my ($left, $right);
+
+	($left, $right) = &_psplit($minnum, \$isleft);
+	for ( my $i = 0; $i < $left; $i++ ) {
+		&_insert(\@lpass, $lnums->[rand @$lnums]);
+	}
+	for ( my $i = 0; $i < $right; $i++ ) {
+		&_insert(\@rpass, $rnums->[rand @$rnums]);
+	}
+
+	($left, $right) = &_psplit($minlower, \$isleft);
+	for ( my $i = 0; $i < $left; $i++ ) {
+		&_insert(\@lpass, $lkeys->[rand @$lkeys]);
+	}
+	for ( my $i = 0; $i < $right; $i++ ) {
+		&_insert(\@rpass, $rkeys->[rand @$rkeys]);
+	}
+
+	($left, $right) = &_psplit($minupper, \$isleft);
+	for ( my $i = 0; $i < $left; $i++ ) {
+		&_insert(\@lpass, uc $lkeys->[rand @$lkeys]);
+	}
+	for ( my $i = 0; $i < $right; $i++ ) {
+		&_insert(\@rpass, uc $rkeys->[rand @$rkeys]);
+	}
+
+	($left, $right) = &_psplit($minspecial, \$isleft);
+	for ( my $i = 0; $i < $left; $i++ ) {
+		&_insert(\@lpass, $lspec->[rand @$lspec]);
+	}
+	for ( my $i = 0; $i < $right; $i++ ) {
+		&_insert(\@rpass, $rspec->[rand @$rspec]);
+	}
+
+	# Merge results together.
+	my $lpass = join "", map { defined $_ ? $_ : () } @lpass;
+	my $rpass = join "", map { defined $_ ? $_ : () } @rpass;
+
+	return $initially_left ? "$lpass$rpass" : "$rpass$lpass";
+}
+
+# Insert $char into password at a random position, thereby spreading the
+# different kinds of characters throughout the password.
+sub _insert {
+	my $pass	= shift;	# ref = ARRAY
+	my $char	= shift;
+
+	my $pos;
+	do {
+		$pos = int rand(1 + @$pass);
+	} while ( defined $pass->[$pos] );
+
+	$pass->[$pos] = $char;
+}
+
+# Given a size, distribute between left and right hands, taking into account
+# where we left off.
+sub _psplit {
+	my $max		= shift;
+	my $isleft	= shift;	# ref = SCALAR
+
+	my ($left, $right);
+
+	if ( $$isleft ) {
+		$right = int($max / 2);
+		$left = $max - $right;
+		$$isleft = !($max % 2);
+	} else {
+		$left = int($max / 2);
+		$right = $max - $left;
+		$$isleft = !($max % 2);
+	}
+
+	return ($left, $right);
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+String::MkPasswd - random password generator
+
+=head1 SYNOPSIS
+
+  use String::MkPasswd qw(mkpasswd);
+
+  print mkpasswd();
+
+  # for the masochisticly paranoid...
+  print mkpasswd(
+      -length     => 27,
+      -minnum     => 5,
+      -minlower   => 1,   # minlower is increased if necessary
+      -minupper   => 5,
+      -minspecial => 5,
+      -distribute => 1,
+  );
+
+=head1 ABSTRACT
+
+This Perl library defines a single function, C<mkpasswd()>, to generate
+random passwords.  The function is meant to be a simple way for
+developers and system administrators to easily generate a relatively
+secure password.
+
+=head1 DESCRIPTION
+
+The exportable C<mkpasswd()> function returns a single scalar: a random
+password.  By default, this password is nine characters long with a
+random distribution of four lower-case characters, two upper-case
+characters, two digits, and one non-alphanumeric character.  These
+parameters can be tuned by the user, as described in the L</"ARGUMENTS">
+section.
+
+=head2 ARGUMENTS
+
+The C<mkpasswd()> function takes an optional hash of arguments.
+
+=over 4
+
+=item -length
+
+The total length of the password.  The default is 9.
+
+=item -minnum
+
+The minimum number of digits that will appear in the final password.
+The default is 2.
+
+=item -minlower
+
+The minimum number of lower-case characters that will appear in the
+final password.  The default is 2.
+
+=item -minupper
+
+The minimum number of upper-case characters that will appear in the
+final password.  The default is 2.
+
+=item -minspecial
+
+The minimum number of non-alphanumeric characters that will appear in
+the final password.  The default is 1.
+
+=item -distribute
+
+If set to a true value, 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.  The
+default is false.
+
+=item -fatal
+
+If set to a true value, C<mkpasswd()> will L<Carp::croak()> rather than
+return C<undef> on error.  The default is false.
+
+=back
+
+If B<-minnum>, B<-minlower>, B<-minupper>, and B<-minspecial> do not add
+up to B<-length>, B<-minlower> will be increased to compensate.
+However, if B<-minnum>, B<-minlower>, B<-minupper>, and B<-minspecial>
+add up to more than B<-length>, then C<mkpasswd()> will return C<undef>.
+See the section entitled L</"EXCEPTION HANDLING"> for how to change this
+behavior.
+
+=head2 EXCEPTION HANDLING
+
+By default, C<mkpasswd()> will return C<undef> if it cannot generate a
+password.  Some people are inclined to exception handling, so
+B<String::MkPasswd> does its best to accomodate them.  If the variable
+C<$String::MkPasswd::FATAL> is set to a true value, C<mkpasswd()> will
+L<Carp::croak()> with an error instead of returning C<undef>.
+
+=head2 EXPORT
+
+None by default.  The C<mkpasswd()> method is exportable.
+
+=head1 SEE ALSO
+
+L<http://expect.nist.gov/#examples>, L<mkpasswd(1)>
+
+=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 at 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

Added: branches/upstream/libstring-mkpasswd-perl/current/perl-String-MkPasswd.spec
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/perl-String-MkPasswd.spec?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/perl-String-MkPasswd.spec (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/perl-String-MkPasswd.spec Sun Mar 16 00:43:04 2008
@@ -1,0 +1,71 @@
+%define module      String-MkPasswd
+%define query       String%3A%3AMkPasswd
+%define perldir     %{_libdir}/perl5
+%define perlversion %(perl -V:version | cut -d\\' -f2)
+
+# Provide perl-specific find-{provides,requires}.
+%define __find_provides /usr/lib/rpm/find-provides.perl
+%define __find_requires /usr/lib/rpm/find-requires.perl
+
+Summary: A random password generator for Perl 5.
+Name: perl-%{module}
+Version: 0.02
+Release: 1
+URL: http://search.cpan.org/search?query=%{query}
+License: Artistic
+Group: Applications/CPAN
+Source: %{module}-%{version}.tar.gz
+Requires: perl >= 5.6.1
+Requires: perl(File::Basename)
+Requires: perl(Getopt::Long)
+Requires: perl(Text::Wrap)
+BuildArch: noarch
+BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
+BuildRequires: perl >= 5.6.1
+BuildRequires: perl(Test::More)
+BuildPrereq: perl(File::Basename)
+BuildPrereq: perl(Getopt::Long)
+BuildPrereq: perl(Text::Wrap)
+
+%description
+The String::MkPasswd module provides the mkpasswd() function which, by
+default, will return a fairly secure password.  The number of letters,
+numbers and special characters in the password can be customized.
+
+The mkpasswd.pl program is also included as a front-end to the
+mkpasswd() function.
+
+%prep
+%setup -q -n %{module}-%{version} 
+
+%build
+%{__perl} Makefile.PL PREFIX=%{buildroot}/usr INSTALLDIRS=vendor
+%{__make}
+
+%install
+[ -n "%{buildroot}" -a "%{buildroot}" != "/" ] && rm -rf %{buildroot}
+%makeinstall
+
+# We install everything into `vendor_perl' so the `$version' dir isn't needed.
+%{__rm} -rf %{buildroot}%{perldir}/%{perlversion}
+
+%clean
+[ -n "%{buildroot}" -a "%{buildroot}" != "/" ] && rm -rf %{buildroot}
+
+%files
+%defattr(-,root,root)
+%doc Changes README
+%{_bindir}/*
+%{_libdir}/perl5/*
+%{_mandir}/*/*
+
+%changelog
+* Wed Mar 17 2004 Chris Grau <cgrau at cpan.org> 0.02-1
+- Applied changes from Adrian Gee <adrian.gee at anu.edu.au> allowing
+  -minnum, -minlower, -minupper and -minspecial to be zero in the call
+  to mkpasswd().
+- Added --no{num,lower,upper,special} options to mkpasswd.pl as
+  alternatives to --min{num,lower,upper,special}=0.
+
+* Thu Nov 13 2003 Chris Grau <cgrau at cpan.org> 0.01-1
+- Initial .spec file generation.

Added: branches/upstream/libstring-mkpasswd-perl/current/t/01use.t
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/t/01use.t?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/t/01use.t (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/t/01use.t Sun Mar 16 00:43:04 2008
@@ -1,0 +1,7 @@
+use Test::More tests => 3;
+BEGIN { use_ok('String::MkPasswd') };
+
+my $passwd = String::MkPasswd::mkpasswd();
+
+ok(defined $passwd, "defined");
+ok(length $passwd > 0, "length");

Added: branches/upstream/libstring-mkpasswd-perl/current/t/02length.t
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/t/02length.t?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/t/02length.t (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/t/02length.t Sun Mar 16 00:43:04 2008
@@ -1,0 +1,14 @@
+use Test::More tests => 22;
+BEGIN { use_ok('String::MkPasswd') };
+
+String::MkPasswd->import("mkpasswd");
+
+ok(length mkpasswd(-length => 0) == 9, "length = 0");
+
+for ( 1 .. 6 ) {
+	ok(!defined mkpasswd(-length => $_), "length = $_");
+}
+
+for ( 7 .. 20 ) {
+	ok(length mkpasswd(-length => $_) == $_, "length = $_");
+}

Added: branches/upstream/libstring-mkpasswd-perl/current/t/03count.t
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/t/03count.t?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/t/03count.t (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/t/03count.t Sun Mar 16 00:43:04 2008
@@ -1,0 +1,121 @@
+use Test::More tests => 41;
+BEGIN { use_ok('String::MkPasswd') };
+
+String::MkPasswd->import("mkpasswd");
+
+my $passwd = mkpasswd();
+
+ok(length $passwd == 9, "length = 9");
+ok(&count_digits($passwd) == 2, "digits = 2");
+ok(&count_lower($passwd) == 4, "lower = 4");
+ok(&count_upper($passwd) == 2, "upper = 2");
+ok(&count_special($passwd) == 1, "special = 1");
+
+$passwd = mkpasswd(
+	-length		=> 20,
+	-minnum		=> 4,
+	-minlower	=> 7,
+	-minupper	=> 6,
+	-minspecial	=> 3,
+);
+
+ok(length $passwd == 20, "length = 20");
+ok(&count_digits($passwd) == 4, "digits = 4");
+ok(&count_lower($passwd) == 7, "lower = 7");
+ok(&count_upper($passwd) == 6, "upper = 6");
+ok(&count_special($passwd) == 3, "special = 3");
+
+$passwd = mkpasswd(
+	-minnum	=> 0,
+);
+
+ok(length $passwd == 9, "length = 9");
+ok(&count_digits($passwd) == 0, "digits = 0");
+ok(&count_lower($passwd) == 6, "lower = 6");
+ok(&count_upper($passwd) == 2, "upper = 2");
+ok(&count_special($passwd) == 1, "special = 1");
+
+$passwd = mkpasswd(
+	-minlower	=> 0,
+);
+
+ok(length $passwd == 9, "length = 9");
+ok(&count_digits($passwd) == 2, "digits = 2");
+ok(&count_lower($passwd) == 4, "lower = 4");
+ok(&count_upper($passwd) == 2, "upper = 2");
+ok(&count_special($passwd) == 1, "special = 1");
+
+$passwd = mkpasswd(
+	-minupper	=> 0,
+);
+
+ok(length $passwd == 9, "length = 9");
+ok(&count_digits($passwd) == 2, "digits = 2");
+ok(&count_lower($passwd) == 6, "lower = 6");
+ok(&count_upper($passwd) == 0, "upper = 0");
+ok(&count_special($passwd) == 1, "special = 1");
+
+$passwd = mkpasswd(
+	-minspecial	=> 0,
+);
+
+ok(length $passwd == 9, "length = 9");
+ok(&count_digits($passwd) == 2, "digits = 2");
+ok(&count_lower($passwd) == 5, "lower = 5");
+ok(&count_upper($passwd) == 2, "upper = 2");
+ok(&count_special($passwd) == 0, "special = 0");
+
+$passwd = mkpasswd(
+	-minnum		=> 0,
+	-minlower	=> 0,
+	-minupper	=> 0,
+	-minspecial	=> 0,
+);
+
+ok(length $passwd == 9, "length = 9");
+ok(&count_digits($passwd) == 0, "digits = 0");
+ok(&count_lower($passwd) == 9, "lower = 9");
+ok(&count_upper($passwd) == 0, "upper = 0");
+ok(&count_special($passwd) == 0, "special = 0");
+
+$passwd = mkpasswd(
+	-length		=> 3,
+	-minnum		=> 3,
+	-minlower	=> 0,
+	-minupper	=> 0,
+	-minspecial	=> 0,
+);
+
+ok(length $passwd == 3, "length = 3");
+ok(&count_digits($passwd) == 3, "digits = 3");
+ok(&count_lower($passwd) == 0, "lower = 0");
+ok(&count_upper($passwd) == 0, "upper = 0");
+ok(&count_special($passwd) == 0, "special = 0");
+
+sub count_digits {
+	my $re = qr/([0-9])/;
+	my $count = 0;
+	$count++ while $_[0] =~ /$re/g;
+	return $count;
+}
+
+sub count_lower {
+	my $re = qr/([a-z])/;
+	my $count = 0;
+	$count++ while $_[0] =~ /$re/g;
+	return $count;
+}
+
+sub count_special {
+	my $re = qr/([!@#\$%~^&*()=_+\[\]{}\\|;:'"<>,.?\/-])/;
+	my $count = 0;
+	$count++ while $_[0] =~ /$re/g;
+	return $count;
+}
+
+sub count_upper {
+	my $re = qr/([A-Z])/;
+	my $count = 0;
+	$count++ while $_[0] =~ /$re/g;
+	return $count;
+}

Added: branches/upstream/libstring-mkpasswd-perl/current/t/04fatal.t
URL: http://svn.debian.org/wsvn/branches/upstream/libstring-mkpasswd-perl/current/t/04fatal.t?rev=17497&op=file
==============================================================================
--- branches/upstream/libstring-mkpasswd-perl/current/t/04fatal.t (added)
+++ branches/upstream/libstring-mkpasswd-perl/current/t/04fatal.t Sun Mar 16 00:43:04 2008
@@ -1,0 +1,20 @@
+use Test::More tests => 5;
+BEGIN { use_ok('String::MkPasswd') };
+
+String::MkPasswd->import("mkpasswd");
+
+$String::MkPasswd::FATAL = 0;
+
+eval { mkpasswd(-fatal => 1) };
+is($@, "", "not fatal, flag");
+
+eval { mkpasswd(-length => 1, -fatal => 1) };
+isnt($@, "", "fatal, flag");
+
+$String::MkPasswd::FATAL = 1;
+
+eval { mkpasswd() };
+is($@, "", "not fatal, global");
+
+eval { mkpasswd(-length => 1) };
+isnt($@, "", "fatal, global");




More information about the Pkg-perl-cvs-commits mailing list