App-Genpass
view release on metacpan or search on metacpan
my %module_build_args = (
"build_requires" => {
"Module::Build" => "0.28"
},
"configure_requires" => {
"ExtUtils::MakeMaker" => 0,
"Module::Build" => "0.28"
},
"dist_abstract" => "Quickly and easily create secure passwords",
"dist_author" => [
"Sawyer X <xsawyerx\@cpan.org>"
],
"dist_name" => "App-Genpass",
"dist_version" => "2.401",
"license" => "perl",
"module_name" => "App::Genpass",
"recursive_test_files" => 1,
"requires" => {
"Carp" => 0,
Revision history for App-Genpass
2.401 14.10.16
* Provide a META.json file.
2.400 12.10.16
* Cleanup Pod. (Brian Manning)
* Create passwords in a more secure fashion (ie not simply rand()).
(Arthur Axel fREW Schmidt)
2.34 04.08.14
* GH #3: When provided some empty types, it would loop forever.
2.33 20.11.12
* Reinstate configuration reading which was removed with the move
to Moo.
* RT #81287: Update docs to reflect Mouse no longer used.
(Props to zaxon)
(Neil Bowers).
- POD fix.
(Tim Heaney)
2.03 03.08.11
(this release, as the previous, are due to Neil Bowers, so thanks!)
- Using readable with special now throws an exception. Added in docs.
- Typo in POD.
2.02 03.08.11
- RT #69980: clarify the usage of default number of passwords in
generate() method. (reported by Neil Bowers, thanks!)
2.01 10.03.11
- Fix tests by requiring namespace::clean at least 0.2
2.00 17.02.11
** Major change **
- Moving to Mouse instead of Moose. Should work much faster for users
without causing problems.
(since it's a big change, I'm noting this as a very major release)
1.01 18.07.10
- Fixed small test bug, must return from default coderef
- Explaining how much "speeds" noverify adds
(0.1 secs for 500 passwords of 500 char length)
1.00 17.07.10
[API Change]
- renamed "repeat" (-r) to "number" (-n)
- renamed -e to -r.
[Docs]
- Document default configuration files
0.11 16.07.10
0.05 01.01.09
- added documentation for all attributes
- first stable finished release
0.04 01.01.09
- replaced die with Carp's croak
- added test for wantarray options
- adding documentation for wantarray options
0.03 14.12.09
- fixed small bug in password repetition
- adding test that statistically catches it
0.02 11.12.09
- removing special chars, refactored nicely
- added verification process
- more tests
- rewrote some tests
- fixed bug that appeared in original genpass, where unreadable chars
would be inserted into the chars array twice
- removed BUILD
{
"abstract" : "Quickly and easily create secure passwords",
"author" : [
"Sawyer X <xsawyerx@cpan.org>"
],
"dynamic_config" : 0,
"generated_by" : "Dist::Zilla version 6.008, CPAN::Meta::Converter version 2.150001",
"license" : [
"perl_5"
],
"meta-spec" : {
"url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
---
abstract: 'Quickly and easily create secure passwords'
author:
- 'Sawyer X <xsawyerx@cpan.org>'
build_requires:
File::Spec: '0'
IO::Handle: '0'
IPC::Open3: '0'
List::MoreUtils: '0'
Module::Build: '0.28'
Test::Deep: '0'
Test::More: '0'
Makefile.PL view on Meta::CPAN
# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.008.
use strict;
use warnings;
use 5.006;
use ExtUtils::MakeMaker;
my %WriteMakefileArgs = (
"ABSTRACT" => "Quickly and easily create secure passwords",
"AUTHOR" => "Sawyer X <xsawyerx\@cpan.org>",
"BUILD_REQUIRES" => {
"Module::Build" => "0.28"
},
"CONFIGURE_REQUIRES" => {
"ExtUtils::MakeMaker" => 0,
"Module::Build" => "0.28"
},
"DISTNAME" => "App-Genpass",
"EXE_FILES" => [
use App::Genpass;
my $genpass = App::Genpass->new();
print $genpass->generate, "\n";
$genpass = App::Genpass->new( readable => 0, length => 20 );
print "$_\n" for $genpass->generate(10);
DESCRIPTION
If you've ever needed to create 10 (or even 10,000) passwords on the
fly with varying preferences (lowercase, uppercase, no confusing
characters, special characters, minimum length, etc.), you know it can
become a pretty pesky task.
This module makes it possible to create flexible and secure passwords,
quickly and easily.
use App::Genpass;
my $genpass = App::Genpass->new();
my $single_password = $genpass->generate(1); # returns scalar
my @single_password = $genpass->generate(1); # returns array
my @multiple_passwords = $genpass->generate(10); # returns array again
my $multiple_passwords = $genpass->generate(10); # returns arrayref
This distribution includes a program called genpass, which is a command
line interface to this module. If you need a program that generates
passwords, use genpass.
SUBROUTINES/METHODS
new
Creates a new instance. It gets a lot of options.
new_with_options
Creates a new instance while reading the command line parameters.
If one is available, that's what it uses. Otherwise nothing.
You must use the new_with_options method described above for this.
flags
These are boolean flags which change the way App::Genpass works.
number
You can decide how many passwords to create. The default is 1.
This can be overridden per generate so you can have a default of 30
but in a specific case only generate 2, if that's what you want.
readable
Use only readable characters, excluding confusing characters: "o",
"O", "0", "l", "1", "I", and special characters such as '#', '!', '%'
and other symbols.
You can overwrite what characters are considered unreadable under
"character attributes" below.
Default: on.
verify
Verify that every type of character wanted (lowercase, uppercase,
numerical, specials, etc.) are present in the password. This makes it
just a tad slower, but it guarantees the result. Best keep it on.
To emphasize how "slower" it is: if you create 500 passwords of 500
character length, using verify off, will make it faster by 0.1
seconds.
Default: on.
attributes
minlength
The minimum length of password to generate.
Default: 8.
maxlength
The maximum length of password to generate.
Default: 10.
length
Use this if you want to explicitly specify the length of password to
generate.
character attributes
These are the attributes that control the types of characters. One can
change which lowercase characters will be used or whether they will be
used at all, for example.
# only a,b,c,d,e,g will be consdered lowercase and no uppercase at all
my $gp = App::Genpass->new( lowercase => [ 'a' .. 'g' ], uppercase => [] );
specials
All special characters.
Default: [ '!', '@', '#', '$', '%', '^', '&', '*', '(', ')' ].
(not including excluded chars)
generate
This method generates the password or passwords.
It accepts an optional parameter indicating how many passwords to
generate.
$gp = App::Genpass->new();
my @passwords = $gp->generate(300); # 300 passwords to go
If you do not provide a parameter, it will use the default number of
passwords to generate, defined by the attribute number explained above.
This method tries to be tricky and DWIM (or rather, DWYM). That is, if
you request it to generate only one password and use scalar context (my
$p = $gp->generate(1)), it will return a single password.
However, if you try to generate multiple passwords and use scalar
context (my $p = $gp->generate(30)), it will return an array reference
for the passwords.
Generating passwords with list context (my @p = $gp->generate(...))
will always return a list of the passwords, even if it's a single
password.
get_config_from_file
Reads the configuration file using Config::Any.
Shamelessly lifted from MooseX::SimpleConfig.
AUTHOR
Sawyer X, <xsawyerx at cpan.org>
bin/genpass view on Meta::CPAN
#!perl
package
genpass;
# ABSTRACT: Quickly and easily create secure passwords
use strict;
use warnings;
use App::Genpass;
my $app = App::Genpass->new_with_options;
my @passwords = $app->generate();
print map { "$_\n" } @passwords;
exit 0;
__END__
=pod
=encoding UTF-8
=head1 NAME
genpass - Quickly and easily create secure passwords
=head1 VERSION
version 2.401
=head1 SYNOPSIS
genpass [-rlnsv] [long options...]
Options:
--configfile configuration file to read (YAML, JSON, INI, etc.)
-r --readable create readable passwords
-l --length password length
-n --number how many passwords to create
-s --special use special characters (clashes with readable opt)
-v --verify verify types of characters
--lowercase what lowercase characters to use
--uppercase what uppercase characters to use
--numerical what numerical characters to use
--specials what characters are considered special
--unreadable what characters are considered unreadable
--usage brief usage output
--help what you're currently reading
=head1 DESCRIPTION
B<genpass> creates passwords in a fast and comfortable maner. The idea is to be
able to do plenty without necessarily needing to.
The way B<genpass> works is by compiling a list of known characters by types
(numerical, lowercase, uppercase, etc.) and a list of unreadable characters -
which are basically characters that can be confused with each other (0, O, I, l,
1 and so on). It generates a random by possible characters, excluding the
non-readable ones, if any exist.
B<genpass> allows you to pick which characters it will use to create the
passwords via the longer options for I<lowercase>, I<uppercase>,
I<numerical>, I<specials> and I<unreadable>.
Also, any boolean option (readable, special) can be negated using "no", such as
I<genpass --nospecial> which negates I<genpass --special>.
B<genpass> also supports configuration files, so you don't have to remember all
your favorite options and insert them each time. First it tries to read a
C<.genpass.yaml> in your home folder (works with Linux, BSD, MacOS, Windows and
anything L<File::HomeDir> supports) and if that doesn't exist (or is simply
unreadable), it looks for a global Unix-style conf named C</etc/genpass.yaml>.
bin/genpass view on Meta::CPAN
genpass --configfile ~/.genpass.yaml
Or a global one as such:
genpass --configfile /etc/genpass.json
Default: I<YourHomeFolder/.genpass.yaml>, then I</etc/genpass.yaml>.
=item B<-r | --readable>
A flag to decide whether passwords should be readable. The purpose of
readability is to create passwords you can give to users or read to someone -
both of which aren't necessarily good practices, but commonly used.
Readable passwords do not contain the additional type of special characters,
which is something to consider. Sometimes it doesn't matter as much (such as a
Windows user on a local LAN machine that has no critical data or access
anywhere.
genpass --readable
Since I<readable> is on by default, you can negate this if you want by using
the I<noreadable> option:
genpass --noreadable
This will turn on the special and possibly unreadable characters option.
Please view I<unreadable> below for more details.
Default: on.
=item B<-l | --length>
The length of the password.
# create a 50 character long password
genpass --length 50
# create a 7 character long password
genpass -l 7
If your configuration requires a certain variety of characters but you've asked
for a shorter password (one which cannot contain that variety), B<genpass> will
complain and try to explain what the problem is.
$ genpass -l 2
You wanted a longer password that the variety of characters you've selected.
You requested 3 types of characters but only have 2 length.
Default: 10.
=item B<-n | --number>
How many passwords to create.
# generate 30 passwords
genpass -n 30
Default: 1.
=item B<-s | --special>
Indicates whether to use special characters or not. This basically means symbols
such as period, exclamation mark, percentage sign, etc.
genpass --special
bin/genpass view on Meta::CPAN
You can negate this flag by doing:
genpass --nospecial
Default: no.
=item B<-v | --verify>
Whether to verify that the variety of characters you requested is included.
Disabling this gains you speed if you create a rather large number of passwords
that have a rather large number of characters. Then you don't need to worry as
much about having that variety since probability says you probably will.
You can negate this using:
genpass --noverify
Best to keep it on though.
Default: yes.
bin/genpass view on Meta::CPAN
Which characters are considered unreadable?
This includes a short list of characters that are easily confused and the above
sequences are stripped of such characters.
=back
=head1 EXAMPLES
# create a 10 character length password
genpass -l 10
# create 30 passwords using all possible characters
genpass -n 30 --noreadable
# create 5 new passwords of length of 30, long options
genpass --number 5 --length 30
=head1 AUTHOR
Sawyer X <xsawyerx@cpan.org>
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Sawyer X.
lib/App/Genpass.pm view on Meta::CPAN
package App::Genpass;
# ABSTRACT: Quickly and easily create secure passwords
$App::Genpass::VERSION = '2.401';
use Carp;
use Moo;
use Sub::Quote 'quote_sub';
use MooX::Types::MooseLike::Base qw/Int Str Bool ArrayRef/;
use Getopt::Long qw/:config no_ignore_case/;
use File::Spec;
use Config::Any;
use File::HomeDir;
use List::AllUtils qw( any none shuffle );
lib/App/Genpass.pm view on Meta::CPAN
# make both refs
return [ \@types, @chars ];
}
sub generate {
my ( $self, $number ) = @_;
my $length;
my $verify = $self->verify;
my @passwords = ();
my @verifications = ();
my $EMPTY = q{};
my ( $char_types, @chars ) = @{ $self->_get_chars };
my @char_types = @{$char_types};
my $num_of_types = scalar @char_types;
if ( (defined($self->length) && $num_of_types > $self->length)
|| ($num_of_types > $self->minlength) ) {
$length = defined($self->length) ? $self->length : $self->minlength.' minimum';
croak <<"_DIE_MSG";
You wanted a shorter password that the variety of characters you've selected.
You requested $num_of_types types of characters but only have $length length.
_DIE_MSG
}
if ($self->minlength > $self->maxlength) {
carp "minlength > maxlength, so I'm switching them";
my $min = $self->maxlength;
$self->maxlength($self->minlength);
$self->minlength($min);
}
$length = $self->length
|| $self->minlength + int(_rand(abs($self->maxlength - $self->minlength) + 1));
$number ||= $self->number;
# each password iteration needed
foreach my $pass_iter ( 1 .. $number ) {
my $password = $EMPTY;
my $char_type = shift @char_types;
# generating the password
while ( $length > length $password ) {
my $char = $chars[ int _rand @chars ];
# for verifying, we just check that it has small capital letters
# if that doesn't work, we keep asking it to get a new random one
# the check if it has large capital letters and so on
if ( $verify && $char_type && @{ $self->$char_type } ) {
# verify $char_type
if ( @{ $self->$char_type } ) {
while ( ! any { $_ eq $char } @{ $self->$char_type } ) {
$char = $chars[ int _rand @chars ];
}
}
$char_type =
scalar @char_types > 0 ? shift @char_types : $EMPTY;
}
$password .= $char;
}
# since the verification process creates a situation of ordered types
# (lowercase, uppercase, numerical, special)
# we need to shuffle the string
$password = join $EMPTY, shuffle( split //sm, $password );
$number == 1 && return $password;
push @passwords, $password;
@char_types = @{$char_types};
}
return wantarray ? @passwords : \@passwords;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::Genpass - Quickly and easily create secure passwords
=head1 VERSION
version 2.401
=head1 SYNOPSIS
use App::Genpass;
my $genpass = App::Genpass->new();
print $genpass->generate, "\n";
$genpass = App::Genpass->new( readable => 0, length => 20 );
print "$_\n" for $genpass->generate(10);
=head1 DESCRIPTION
If you've ever needed to create 10 (or even 10,000) passwords on the fly with
varying preferences (lowercase, uppercase, no confusing characters, special
characters, minimum length, etc.), you know it can become a pretty pesky task.
This module makes it possible to create flexible and secure passwords, quickly
and easily.
use App::Genpass;
my $genpass = App::Genpass->new();
my $single_password = $genpass->generate(1); # returns scalar
my @single_password = $genpass->generate(1); # returns array
my @multiple_passwords = $genpass->generate(10); # returns array again
my $multiple_passwords = $genpass->generate(10); # returns arrayref
This distribution includes a program called B<genpass>, which is a command line
interface to this module. If you need a program that generates passwords, use
B<genpass>.
=for stopwords boolean DWIM DWYM arrayref perldoc Github CPAN's AnnoCPAN CPAN
=head1 SUBROUTINES/METHODS
=head2 new
Creates a new instance. It gets a lot of options.
lib/App/Genpass.pm view on Meta::CPAN
You must use the C<new_with_options> method described above for this.
=head3 flags
These are boolean flags which change the way App::Genpass works.
=over 4
=item number
You can decide how many passwords to create. The default is 1.
This can be overridden per I<generate> so you can have a default of 30 but in a
specific case only generate 2, if that's what you want.
=item readable
Use only readable characters, excluding confusing characters: "o", "O", "0",
"l", "1", "I", and special characters such as '#', '!', '%' and other symbols.
You can overwrite what characters are considered unreadable under "character
attributes" below.
Default: on.
=item verify
Verify that every type of character wanted (lowercase, uppercase, numerical,
specials, etc.) are present in the password. This makes it just a tad slower,
but it guarantees the result. Best keep it on.
To emphasize how "slower" it is: if you create 500 passwords of 500 character
length, using C<verify> off, will make it faster by 0.1 seconds.
Default: on.
=back
=head3 attributes
=over 4
=item minlength
The minimum length of password to generate.
Default: 8.
=item maxlength
The maximum length of password to generate.
Default: 10.
=item length
Use this if you want to explicitly specify the length of password to generate.
=back
=head3 character attributes
These are the attributes that control the types of characters. One can change
which lowercase characters will be used or whether they will be used at all,
for example.
# only a,b,c,d,e,g will be consdered lowercase and no uppercase at all
lib/App/Genpass.pm view on Meta::CPAN
All special characters.
Default: [ '!', '@', '#', '$', '%', '^', '&', '*', '(', ')' ].
(not including excluded chars)
=back
=head2 generate
This method generates the password or passwords.
It accepts an optional parameter indicating how many passwords to generate.
$gp = App::Genpass->new();
my @passwords = $gp->generate(300); # 300 passwords to go
If you do not provide a parameter, it will use the default number of passwords
to generate, defined by the attribute B<number> explained above.
This method tries to be tricky and DWIM (or rather, DWYM). That is, if you
request it to generate only one password and use scalar context
(C<< my $p = $gp->generate(1) >>), it will return a single password.
However, if you try to generate multiple passwords and use scalar context
(C<< my $p = $gp->generate(30) >>), it will return an array reference for the
passwords.
Generating passwords with list context (C<< my @p = $gp->generate(...) >>)
will always return a list of the passwords, even if it's a single password.
=head2 get_config_from_file
Reads the configuration file using L<Config::Any>.
Shamelessly lifted from L<MooseX::SimpleConfig>.
=head1 AUTHOR
Sawyer X, C<< <xsawyerx at cpan.org> >>
t/03-generate_chars.t view on Meta::CPAN
use strict;
use warnings;
use App::Genpass;
use List::MoreUtils 'any';
use Test::More tests => (4 + 3)*10;
sub test_types {
my ( $app, @types ) = @_;
my $attempts = 10;
my @passwords = $app->generate($attempts);
foreach my $pass (@passwords) {
my @pass = split //, $pass;
my %appear = ();
#use Data::Dumper; print Dumper \@pass;
foreach my $type (@types) {
my @type_chars = @{ $app->$type };
foreach my $type_char (@type_chars) {
if ( any { $_ eq $type_char } @pass ) {
$appear{$type}++;
t/04-variable_length.t view on Meta::CPAN
}
ok(int(keys %seen) == 4 && $seen{7} && $seen{8} && $seen{9} && $seen{10},
"reversed minlength and maxlength");
%seen = ();
$app = App::Genpass->new(minlength => 8, maxlength => 8);
for (my $i=0; $i<1000; $i++) {
$pass = $app->generate();
$seen{ length($pass) } = 1;
}
ok(int(keys %seen) == 1 && $seen{8}, "min=8, max=8: should only see passwords of length 8");
%seen = ();
$app = App::Genpass->new(length => 8);
for (my $i=0; $i<1000; $i++) {
$pass = $app->generate();
$seen{ length($pass) } = 1;
}
ok(int(keys %seen) == 1 && $seen{8}, "only seen passwords of length 8");
%seen = ();
$app = App::Genpass->new();
for (my $i=0; $i<1000; $i++) {
$pass = $app->generate();
$seen{ length($pass) } = 1;
}
ok(int(keys %seen) == 3 && $seen{8} && $seen{9} && $seen{10},
"default should be lengths >= 8 and <= 10");
t/wantarray.t view on Meta::CPAN
# this tests the wantarray options
use strict;
use warnings;
use App::Genpass;
use Test::More tests => 6;
my $app = App::Genpass->new;
my $password = $app->generate(1);
my @passwords = $app->generate(1);
my @many_passwords = $app->generate(10);
my $many_passwords = $app->generate(10);
is( ref \$password, 'SCALAR', 'single generate - scalar' );
is( ref \@passwords, 'ARRAY', 'single generate - array' );
is( ref \@many_passwords, 'ARRAY', 'multiple generate - array' );
is( ref $many_passwords, 'ARRAY', 'multiple generate - scalar' );
cmp_ok( scalar @passwords, '==', 1, 'only 1 item in single array' );
cmp_ok( scalar @many_passwords, '==', 10, 'only 10 items in multiple array' );
( run in 0.651 second using v1.01-cache-2.11-cpan-49f99fa48dc )