blib/lib/Data/Password/Check/JPassword.pm

filter: Statementstmt 63.1% 36 / 57 Branchbran 62.5% 10 / 16 Conditioncond 88.8% 8 / 9 MC/DCmcdc 83.3% 5 / 6 Subroutinesub 42.8% 6 / 14 Podpod 100% 10 / 10 totaltotal 66.9% 75 / 112 CC 13 SCAR 20.4
CC
13
Cov
66%
advice
20.0
security
10.1
is_strong
2.0
CRAP 7.7
↑ Summary
1 package Data::Password::Check::JPassword;
2  
3 4 ▶use 5.008008;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 require Exporter;
8 4 ▶use POSIX qw( floor log );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 our @ISA = qw(Exporter);
11 4 our %EXPORT_TAGS = ( 'all' => [ qw(
12 password_check
13 ) ] );
14  
15 4 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
16  
17 4 our @EXPORT = qw(
18 security is_weak is_strong is_medium advice
19 password_security
20 password_strong
21 password_medium
22 password_weak
23 password_advice
24 );
25  
26 4 our $VERSION = '0.02';
27  
28  
29 ###########################################################
30 sub security
31 8 ▶{
Subroutine security: called CC=10 SCAR=23.1
Pod documented
32 8 my( $package, $password ) = @_;
33 8 ▶ return $password if ref $password;
Branch: 1 branch
BranchTrueFalseTotal
if ref $password 0 8 8
34 8 $password =~ s/^(\s+)|(\s+$)//g;
35 8 my $c = {number=>1, uppercase=>1, lowercase=>1, punctuation=>1, special=>1};
36 8 ▶ while( $password =~ /(.)/g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($password =~ /(.)/g) 78 8 86
37 78 my $char = ord $1;
38 78 ▶ if( $char > 127 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($char > 127) 0 78 78
39 0 $c->{special}++;
40 }
41 78 ▶ if( $char > 47 && $char < 58 ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($char > 47 and $char < 58) { } 4 74 78
elsif ($char > 64 and $char < 91) { } 24 50 74
elsif ($char > 96 and $char < 123) { } 42 8 50
Condition100%3/3
$char > 47 and $char < 58
!ll&&!rl&&r
8664
MC/DC100%2/2
$char > 47 and $char < 58
$char > 47 $char < 58
Truth table100%3/3
A and B
A= $char > 47B= $char < 58
ABresult
0X0
100
111
42 4 $c->{number} ++;
43 }
44 ▶ elsif( $char > 64 && $char < 91 ) {
Condition100%3/3
$char > 64 and $char < 91
!ll&&!rl&&r
84224
MC/DC100%2/2
$char > 64 and $char < 91
$char > 64 $char < 91
Truth table100%3/3
A and B
A= $char > 64B= $char < 91
ABresult
0X0
100
111
45 24 $c->{uppercase} ++;
46 }
47 ▶ elsif( $char > 96 && $char < 123 ) {
Condition66%2/3
$char > 96 and $char < 123
!ll&&!rl&&r
8042
MC/DC50%1/2
$char > 96 and $char < 123
$char > 96 $char < 123
Truth table66%2/3
A and B
A= $char > 96B= $char < 123
ABresult
0X0
100
111
48 42 $c->{lowercase} ++;
49 }
50 else {
51 8 $c->{punctuation} += 2;
52 }
53 }
54  
55 my $level = $c->{number} * $c->{uppercase} * $c->{lowercase} *
56 8 $c->{punctuation} * $c->{special};
57 # $c->{level} = floor( log( $level*$level ) + 0.5 );
58 # jPassword uses Math.round()... why bother?
59 8 $c->{level} = log( $level*$level );
60 8 $c->{password} = $password;
61 8 return $c
62 }
63  
64 ###########################################################
65 # Return true if this is a strong password
66 sub is_strong
67 0 ▶{
Subroutine is_strong: not called CC=1 SCAR=6.9
Pod documented
68 0 my( $package, $password ) = @_;
69 0 my $c = $package->security( $password );
70 0 return $c->level >= 10;
71 }
72  
73 ###########################################################
74 # Return true if this is a medium-strength password
75 sub is_medium
76 0 ▶{
Subroutine is_medium: not called CC=1 SCAR=6.9
Pod documented
77 0 my( $package, $password ) = @_;
78 0 my $c = $package->security( $password );
79 0 return $c->level >= 5;
80 }
81  
82 ###########################################################
83 # Return true if this is a weak password
84 sub is_weak
85 0 ▶{
Subroutine is_weak: not called CC=1 SCAR=6.9
Pod documented
86 0 my( $package, $password ) = @_;
87 0 my $c = $package->security( $password );
88 0 return $c->level < 5;
89 }
90  
91 ###########################################################
92 sub advice
93 0 ▶{
Subroutine advice: not called CC=4 SCAR=30.0
Pod documented
94 0 my( $package, $password ) = @_;
95 0 my $c = password_security( $password );
96 0 ▶ return if password_strong( $c );
Branch: 1 branch
BranchTrueFalseTotal
if password_strong($c) 0 0 0
97 0 foreach my $k ( qw( lowercase uppercase number punctuation special ) ) {
98 0 ▶ return $k if $c->{$k} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $c->{$k} < 2 0 0 0
99 }
100 }
101  
102  
103  
104  
105  
106 ###########################################################
107 sub password_security
108 4 ▶{
Subroutine password_security: called CC=1 SCAR=0.0
Pod documented
109 4 return __PACKAGE__->security( @_ );
110 }
111  
112 ###########################################################
113 sub password_strong
114 0 ▶{
Subroutine password_strong: not called CC=1 SCAR=6.9
Pod documented
115 0 return __PACKAGE__->is_strong( @_ );
116 }
117  
118 ###########################################################
119 # Return true if this is a strong password
120 sub password_medium
121 0 ▶{
Subroutine password_medium: not called CC=1 SCAR=6.9
Pod documented
122 0 return __PACKAGE__->is_medium( @_ );
123 }
124  
125 ###########################################################
126 # Return true if this is a weak password
127 sub password_weak
128 0 ▶{
Subroutine password_weak: not called CC=1 SCAR=6.9
Pod documented
129 0 my( $password ) = @_;
130 0 return __PACKAGE__->is_weak( @_ );
131 }
132  
133 ###########################################################
134 # Return advice for a password
135 sub password_advice
136 0 ▶{
Subroutine password_advice: not called CC=1 SCAR=6.9
Pod documented
137 0 my( $password ) = @_;
138 0 return __PACKAGE__->is_advice( @_ );
139 }
140  
141  
142  
143 4 1;
144  
145 __END__
↑ Summary