| 1 | package Data::Pwgen; | ||||||||||||||||||||
| 2 | { | ||||||||||||||||||||
| 3 | 3 | $Data::Pwgen::VERSION = '0.14'; | |||||||||||||||||||
| 4 | } | ||||||||||||||||||||
| 5 | 3 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 3 | $Data::Pwgen::AUTHORITY = 'cpan:TEX'; | |||||||||||||||||||
| 7 | } | ||||||||||||||||||||
| 8 | # ABSTRACT: simple password generation and assessment | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 12 | 3 | ▶ | use 5.008; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | 3 | ▶ | use parent 'Exporter'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 3 | our @EXPORT_OK = qw(pwgen pwstrength); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | { | ||||||||||||||||||||
| 20 | ## no critic (ProhibitNoisyQuotes) | ||||||||||||||||||||
| 21 | 3 | my %rep = ( | |||||||||||||||||||
| 22 | 'nums' => [ '0' .. '9' ], | ||||||||||||||||||||
| 23 | 'signs' => [ '%', '$', '_', '-', '+', '*', '&', '/', '=', '!', '#' ], | ||||||||||||||||||||
| 24 | 'lower' => [ 'a' .. 'z' ], | ||||||||||||||||||||
| 25 | 'upper' => [ 'A' .. 'Z' ], | ||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||
| 27 | ## use critic | ||||||||||||||||||||
| 28 | 3 | $rep{'chars'} = [ @{ $rep{'lower'} }, @{ $rep{'upper'} } ]; | |||||||||||||||||||
| 29 | 3 | $rep{'alphanum'} = [ @{ $rep{'chars'} }, @{ $rep{'nums'} } ]; | |||||||||||||||||||
| 30 | 3 | $rep{'alphasym'} = [ @{ $rep{'alphanum'} }, @{ $rep{'signs'} } ]; | |||||||||||||||||||
| 31 | 3 | my $entropy = 0; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | ## no critic (ProhibitMagicNumbers) | ||||||||||||||||||||
| 34 | 3 | my $default_length = 16; | |||||||||||||||||||
| 35 | 3 | my $min_length = 8; | |||||||||||||||||||
| 36 | ## use critic | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 102 | ▶ | sub pwgen { | ||||||||||||||||||
|
Subroutine
pwgen: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||||||||||||
| 40 | 102 | ▶ | my $length = shift || $default_length; | ||||||||||||||||||
|
Condition33%1/3
shift() || $default_length
MC/DC0%0/2
shift() || $default_length
shift()
$default_length
Truth table33%1/3
A || B
A= shift()B= $default_length
| |||||||||||||||||||||
| 41 | 102 | ▶ | my $class = shift || 'alphanum'; | ||||||||||||||||||
|
Condition100%2/2
shift() || 'alphanum'
MC/DC100%1/1
shift() || 'alphanum'
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||
| 42 | 102 | ▶ | $rep{$class} or $class = 'alphanum'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 43 | 102 | $entropy++; | |||||||||||||||||||
| 44 | 102 | srand( time() + $entropy ); | |||||||||||||||||||
| 45 | 102 | my $pw = join( q{}, map { $rep{$class}[ rand( $#{ $rep{$class} } ) ] } 0 .. $length - 1 ); | |||||||||||||||||||
| 46 | 102 | return $pw; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 200 | ▶ | sub pwstrength { | ||||||||||||||||||
|
Subroutine
pwstrength: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||
| 51 | 200 | my $pw = shift; | |||||||||||||||||||
| 52 | 200 | my $strength = 0; | |||||||||||||||||||
| 53 | 200 | $strength += length($pw) - ($min_length+1); | |||||||||||||||||||
| 54 | 200 | ▶ | $strength++ if ( $pw =~ m/[a-z]/ ); # lower case alpha | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 200 | ▶ | $strength++ if ( $pw =~ m/[A-Z]/ ); # upper case alpha | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 56 | 200 | ▶ | $strength++ if ( $pw =~ m/[0-9]/ ); # numbers | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 57 | 200 | ▶ | $strength++ if ( $pw =~ m/[^A-Z0-9]/i ); # non-alphanums | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 58 | 200 | return $strength; | |||||||||||||||||||
| 59 | } | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | 3 | *strength = \&pwstrength; | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 3 | 1; # End of Data::Pwgen | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | __END__ | ||||||||||||||||||||