line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Pwgen; |
2
|
|
|
|
|
|
|
{ |
3
|
|
|
|
|
|
|
$Data::Pwgen::VERSION = '0.14'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
2
|
|
|
2
|
|
58887
|
$Data::Pwgen::AUTHORITY = 'cpan:TEX'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: simple password generation and assessment |
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
19
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
58
|
|
11
|
2
|
|
|
2
|
|
11
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
12
|
2
|
|
|
2
|
|
65
|
use 5.008; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
107
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1875
|
use parent 'Exporter'; |
|
2
|
|
|
|
|
704
|
|
|
2
|
|
|
|
|
13
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw(pwgen pwstrength); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
{ |
20
|
|
|
|
|
|
|
## no critic (ProhibitNoisyQuotes) |
21
|
|
|
|
|
|
|
my %rep = ( |
22
|
|
|
|
|
|
|
'nums' => [ '0' .. '9' ], |
23
|
|
|
|
|
|
|
'signs' => [ '%', '$', '_', '-', '+', '*', '&', '/', '=', '!', '#' ], |
24
|
|
|
|
|
|
|
'lower' => [ 'a' .. 'z' ], |
25
|
|
|
|
|
|
|
'upper' => [ 'A' .. 'Z' ], |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
## use critic |
28
|
|
|
|
|
|
|
$rep{'chars'} = [ @{ $rep{'lower'} }, @{ $rep{'upper'} } ]; |
29
|
|
|
|
|
|
|
$rep{'alphanum'} = [ @{ $rep{'chars'} }, @{ $rep{'nums'} } ]; |
30
|
|
|
|
|
|
|
$rep{'alphasym'} = [ @{ $rep{'alphanum'} }, @{ $rep{'signs'} } ]; |
31
|
|
|
|
|
|
|
my $entropy = 0; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
## no critic (ProhibitMagicNumbers) |
34
|
|
|
|
|
|
|
my $default_length = 16; |
35
|
|
|
|
|
|
|
my $min_length = 8; |
36
|
|
|
|
|
|
|
## use critic |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub pwgen { |
40
|
102
|
|
33
|
102
|
1
|
55851
|
my $length = shift || $default_length; |
41
|
102
|
|
100
|
|
|
410
|
my $class = shift || 'alphanum'; |
42
|
102
|
50
|
|
|
|
256
|
$rep{$class} or $class = 'alphanum'; |
43
|
102
|
|
|
|
|
118
|
$entropy++; |
44
|
102
|
|
|
|
|
199
|
srand( time() + $entropy ); |
45
|
102
|
|
|
|
|
399
|
my $pw = join( q{}, map { $rep{$class}[ rand( $#{ $rep{$class} } ) ] } 0 .. $length - 1 ); |
|
5082
|
|
|
|
|
6629
|
|
|
5082
|
|
|
|
|
13186
|
|
46
|
102
|
|
|
|
|
728
|
return $pw; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub pwstrength { |
51
|
200
|
|
|
200
|
1
|
52536
|
my $pw = shift; |
52
|
200
|
|
|
|
|
256
|
my $strength = 0; |
53
|
200
|
|
|
|
|
280
|
$strength += length($pw) - ($min_length+1); |
54
|
200
|
100
|
|
|
|
695
|
$strength++ if ( $pw =~ m/[a-z]/ ); # lower case alpha |
55
|
200
|
100
|
|
|
|
500
|
$strength++ if ( $pw =~ m/[A-Z]/ ); # upper case alpha |
56
|
200
|
100
|
|
|
|
571
|
$strength++ if ( $pw =~ m/[0-9]/ ); # numbers |
57
|
200
|
50
|
|
|
|
639
|
$strength++ if ( $pw =~ m/[^A-Z0-9]/i ); # non-alphanums |
58
|
200
|
|
|
|
|
544
|
return $strength; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
*strength = \&pwstrength; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; # End of Data::Pwgen |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |