blib/lib/Data/Pwgen.pm

filter: Statementstmt 100% 48 / 48 Branchbran 70.0% 7 / 10 Conditioncond 60.0% 3 / 5 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 90.6% 68 / 75 CC 8 SCAR 12.0
CC
8
Cov
92%
pwstrength
5.0
pwgen
4.1
BEGIN
1.0
CRAP 3.3
↑ Summary
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
l!l&&r!l&&!r
10200
MC/DC0%0/2
shift() || $default_length
shift() $default_length
Truth table33%1/3
A || B
A= shift()B= $default_length
ABresult
1X1
011
000
41 102 ▶ my $class = shift || 'alphanum';
Condition100%2/2
shift() || 'alphanum'
l!l
2100
MC/DC100%1/1
shift() || 'alphanum'
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
42 102 ▶ $rep{$class} or $class = 'alphanum';
Branch: 1 branch
BranchTrueFalseTotal
$rep{$class} or $class = "alphanum" 102 0 102
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
BranchTrueFalseTotal
if $pw =~ /[a-z]/ 200 0 200
55 200 ▶ $strength++ if ( $pw =~ m/[A-Z]/ ); # upper case alpha
Branch: 1 branch
BranchTrueFalseTotal
if $pw =~ /[A-Z]/ 196 4 200
56 200 ▶ $strength++ if ( $pw =~ m/[0-9]/ ); # numbers
Branch: 1 branch
BranchTrueFalseTotal
if $pw =~ /[0-9]/ 192 8 200
57 200 ▶ $strength++ if ( $pw =~ m/[^A-Z0-9]/i ); # non-alphanums
Branch: 1 branch
BranchTrueFalseTotal
if $pw =~ /[^A-Z0-9]/i 0 200 200
58 200 return $strength;
59 }
60  
61  
62 3 *strength = \&pwstrength;
63 }
64  
65  
66 3 1; # End of Data::Pwgen
67  
68 __END__
↑ Summary