| 1 | package Data::Validate::WithYAML::Plugin::PasswordPolicy; | ||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Plugin to check passwords against a policy | ||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||
| 10 | 1 | our $VERSION = '0.03'; | |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 206 | ▶ | sub check { | ||||||||||||||||||||||||||||||
|
Subroutine
check: called CC=28 SCAR=33.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 13 | 206 | my ($class, $value, $options) = @_; | |||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | 206 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 16 | 192 | ▶ | return if $value eq ''; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||
| 18 | 178 | ▶ | return 1 if !$options; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||
| 20 | 172 | ▶ | my %policy = %{ $options->{'x-policy'} || {} }; | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$options->{'x-policy'} || {}
MC/DC100%1/1
$options->{'x-policy'} || {}
$options->{'x-policy'}
Truth table100%2/2
A
A= $options->{'x-policy'}
| |||||||||||||||||||||||||||||||||
| 21 | 172 | ▶ | return 1 if !%policy; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 140 | my $return = 1; | |||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 140 | ▶ | if ( $policy{length} && $policy{length} =~ /,/ ) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$policy{"length"} and $policy{"length"} =~ /,/
MC/DC100%2/2
$policy{"length"} and $policy{"length"} =~ /,/
$policy{"length"}
$policy{"length"} =~ /,/
Truth table100%3/3
A and B
A= $policy{"length"}B= $policy{"length"} =~ /,/
| |||||||||||||||||||||||||||||||||
| 26 | 90 | my ($min,$max) = $policy{length} =~ /\s*(\d+)\s*,(?:\s*(\d+)\s*)?/; | |||||||||||||||||||||||||||||||
| 27 | 90 | my $bool = 1; | |||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 90 | ▶ | if(defined $min and length $value < $min){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $min and length $value < $min
MC/DC100%2/2
defined $min and length $value < $min
defined $min
length $value < $min
Truth table100%3/3
A and B
A= defined $minB= length $value < $min
| |||||||||||||||||||||||||||||||||
| 30 | 24 | $bool = 0; | |||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 90 | ▶ | if(defined $max and length $value > $max){ | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $max and length $value > $max
MC/DC100%2/2
defined $max and length $value > $max
defined $max
length $value > $max
Truth table100%3/3
A and B
A= defined $maxB= length $value > $max
| |||||||||||||||||||||||||||||||||
| 34 | 12 | $bool = 0; | |||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 90 | $return &= $bool; | |||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||
| 39 | elsif ( $policy{length} ) { | ||||||||||||||||||||||||||||||||
| 40 | 36 | $return &= ( $policy{length} == length $value ); | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||
| 43 | 140 | ▶ | return if !$return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 83 | ▶ | if ( defined $policy{chars} and !ref $policy{chars} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $policy{"chars"} and not ref $policy{"chars"}
MC/DC100%2/2
defined $policy{"chars"} and not ref $policy{"chars"}
defined $policy{"chars"}
not ref $policy{"chars"}
Truth table100%3/3
A and not(B)
A= defined $policy{"chars"}B= not ref $policy{"chars"}
| |||||||||||||||||||||||||||||||||
| 46 | 6 | $policy{chars} = [ $policy{chars} ]; | |||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | CLASS: | ||||||||||||||||||||||||||||||||
| 50 | 83 | ▶ | for my $class ( @{ $policy{chars} || [] } ) { | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$policy{'chars'} || []
MC/DC100%1/1
$policy{'chars'} || []
$policy{'chars'}
Truth table100%2/2
A
A= $policy{'chars'}
| |||||||||||||||||||||||||||||||||
| 51 | 43 | my $re = qr/[$class]/; | |||||||||||||||||||||||||||||||
| 52 | 43 | ▶ | my $matches = $value =~ $re ? 1 : 0; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 53 | 43 | $return &= $matches; | |||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | 43 | ▶ | last CLASS if !$return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 83 | ▶ | return if !$return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 70 | ▶ | if ( defined $policy{chars_blacklist} and !ref $policy{chars_blacklist} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $policy{"chars_blacklist"} and not ref $policy{"chars_blacklist"}
MC/DC100%2/2
defined $policy{"chars_blacklist"} and not ref $policy{"chars_blacklist"}
defined $policy{"chars_blacklist"}
not ref $policy{"chars_blacklist"}
Truth table100%3/3
A and not(B)
A= defined $policy{"chars_blacklist"}B= not ref $policy{"chars_blacklist"}
| |||||||||||||||||||||||||||||||||
| 61 | 9 | $policy{chars_blacklist} = [ $policy{chars_blacklist} ]; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | CLASS: | ||||||||||||||||||||||||||||||||
| 65 | 70 | ▶ | for my $class ( @{ $policy{chars_blacklist} || [] } ) { | ||||||||||||||||||||||||||||||
|
Condition100%2/2
$policy{'chars_blacklist'} || []
MC/DC100%1/1
$policy{'chars_blacklist'} || []
$policy{'chars_blacklist'}
Truth table100%2/2
A
A= $policy{'chars_blacklist'}
| |||||||||||||||||||||||||||||||||
| 66 | 18 | my $re = qr/[$class]/; | |||||||||||||||||||||||||||||||
| 67 | 18 | ▶ | my $matches = $value =~ $re ? 0 : 1; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 18 | $return &= $matches; | |||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||
| 70 | 18 | ▶ | last CLASS if !$return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | 70 | ▶ | return if !$return; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 74 | 64 | return 1; | |||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | 1 | 1; | |||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | __END__ | ||||||||||||||||||||||||||||||||