line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::Validate::WithYAML::Plugin::PasswordPolicy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
52827
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
391
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# ABSTRACT: Plugin to check passwords against a policy |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub check { |
13
|
206
|
|
|
206
|
1
|
49924
|
my ($class, $value, $options) = @_; |
14
|
|
|
|
|
|
|
|
15
|
206
|
100
|
|
|
|
460
|
return unless defined $value; |
16
|
192
|
100
|
|
|
|
434
|
return if $value eq ''; |
17
|
|
|
|
|
|
|
|
18
|
178
|
100
|
|
|
|
337
|
return 1 if !$options; |
19
|
|
|
|
|
|
|
|
20
|
172
|
100
|
|
|
|
228
|
my %policy = %{ $options->{'x-policy'} || {} }; |
|
172
|
|
|
|
|
585
|
|
21
|
172
|
100
|
|
|
|
400
|
return 1 if !%policy; |
22
|
|
|
|
|
|
|
|
23
|
140
|
|
|
|
|
216
|
my $return = 1; |
24
|
|
|
|
|
|
|
|
25
|
140
|
100
|
100
|
|
|
594
|
if ( $policy{length} && $policy{length} =~ /,/ ) { |
|
|
100
|
|
|
|
|
|
26
|
90
|
|
|
|
|
469
|
my ($min,$max) = $policy{length} =~ /\s*(\d+)\s*,(?:\s*(\d+)\s*)?/; |
27
|
90
|
|
|
|
|
161
|
my $bool = 1; |
28
|
|
|
|
|
|
|
|
29
|
90
|
100
|
100
|
|
|
282
|
if(defined $min and length $value < $min){ |
30
|
24
|
|
|
|
|
38
|
$bool = 0; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
90
|
100
|
100
|
|
|
227
|
if(defined $max and length $value > $max){ |
34
|
12
|
|
|
|
|
20
|
$bool = 0; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
90
|
|
|
|
|
141
|
$return &= $bool; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
elsif ( $policy{length} ) { |
40
|
36
|
|
|
|
|
77
|
$return &= ( $policy{length} == length $value ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
140
|
100
|
|
|
|
293
|
return if !$return; |
44
|
|
|
|
|
|
|
|
45
|
83
|
100
|
100
|
|
|
219
|
if ( defined $policy{chars} and !ref $policy{chars} ) { |
46
|
6
|
|
|
|
|
13
|
$policy{chars} = [ $policy{chars} ]; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
CLASS: |
50
|
83
|
100
|
|
|
|
104
|
for my $class ( @{ $policy{chars} || [] } ) { |
|
83
|
|
|
|
|
242
|
|
51
|
43
|
|
|
|
|
253
|
my $re = qr/[$class]/; |
52
|
43
|
100
|
|
|
|
195
|
my $matches = $value =~ $re ? 1 : 0; |
53
|
43
|
|
|
|
|
71
|
$return &= $matches; |
54
|
|
|
|
|
|
|
|
55
|
43
|
100
|
|
|
|
113
|
last CLASS if !$return; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
83
|
100
|
|
|
|
180
|
return if !$return; |
59
|
|
|
|
|
|
|
|
60
|
70
|
100
|
100
|
|
|
157
|
if ( defined $policy{chars_blacklist} and !ref $policy{chars_blacklist} ) { |
61
|
9
|
|
|
|
|
19
|
$policy{chars_blacklist} = [ $policy{chars_blacklist} ]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
CLASS: |
65
|
70
|
100
|
|
|
|
91
|
for my $class ( @{ $policy{chars_blacklist} || [] } ) { |
|
70
|
|
|
|
|
217
|
|
66
|
18
|
|
|
|
|
83
|
my $re = qr/[$class]/; |
67
|
18
|
100
|
|
|
|
69
|
my $matches = $value =~ $re ? 0 : 1; |
68
|
18
|
|
|
|
|
48
|
$return &= $matches; |
69
|
|
|
|
|
|
|
|
70
|
18
|
100
|
|
|
|
48
|
last CLASS if !$return; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
70
|
100
|
|
|
|
136
|
return if !$return; |
74
|
64
|
|
|
|
|
226
|
return 1; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |