OWASP/AbstractBase.pm

filter: Statementstmt 91.7% 67 / 73 Branchbran 100% 18 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 88.2% 15 / 17 Podpod 100% 6 / 6 totaltotal 92.9% 106 / 114 CC 10 SCAR 6.9
CC
10
Cov
93%
check_password
3.0
check_legacy_password
3.0
__ANON__
3.0
CRAP 2.0
↑ Summary OWASP/Argon2.pm »
1 package Password::OWASP::AbstractBase;
2 7 our $VERSION = '0.005';
3 7 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # ABSTRACT: Abstract base class to implement OWASP password recommendations
7  
8 7 ▶use Authen::Passphrase;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Moose::Util::TypeConstraints qw(enum);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 7 requires qw(ppr);
14  
15 7 has cost => (
16 is => 'ro',
17 isa => 'Int',
18 default => 12,
19 );
20  
21 7 has hashing => (
22 is => 'ro',
23 isa => enum([qw(sha1 sha256 sha512 none sha384 sha224)]),
24 lazy => 1,
25 builder => '_build_hashing_default',
26 );
27  
28 7 has update_method => (
29 is => 'ro',
30 isa => 'CodeRef',
31 predicate => 'has_update_method',
32 );
33  
34 6 ▶sub crypt_password {
Subroutine crypt_password: called CC=1 SCAR=0.0
Pod documented
35 6 my $self = shift;
36 6 my $pass = shift;
37 6 my $ppr = $self->ppr->new(
38 cost => $self->cost,
39 salt_random => 1,
40 passphrase => $self->prehash_password($pass),
41 );
42 6 return $ppr->as_rfc2307;
43 }
44  
45 22 ▶sub check_password {
Subroutine check_password: called CC=3 SCAR=11.0
Pod documented
46 22 my $self = shift;
47 22 my $given = shift;
48 22 my $want = shift;
49  
50 22 ▶ my $ok = try {
Subroutine __ANON__: called CC=2 SCAR=6.9
51 22 my $ppr = $self->ppr->from_rfc2307($want);
52 15 ▶ return 1 if $ppr->match($self->prehash_password($given));
Branch: 1 branch
BranchTrueFalseTotal
if $ppr->match($self->prehash_password($given)) 3 12 15
53 22 };
54 22 ▶ return 1 if $ok;
Branch: 1 branch
BranchTrueFalseTotal
if $ok 3 19 22
55 19 ▶ return 1 if $self->check_legacy_password($given, $want);
Branch: 1 branch
BranchTrueFalseTotal
if $self->check_legacy_password($given, $want) 12 7 19
56 7 return 0;
57 }
58  
59 19 ▶sub check_legacy_password {
Subroutine check_legacy_password: called CC=3 SCAR=11.0
Pod documented
60 19 my ($self, $given, $want) = @_;
61  
62 19 ▶ my $ok = try {
Subroutine __ANON__: called CC=3 SCAR=11.0
63 19 my $ppr = $self->ppr->from_rfc2307($want);
64 12 ▶ return 1 if $ppr->match($self->_prehash_password($given));
Branch: 1 branch
BranchTrueFalseTotal
if $ppr->match($self->_prehash_password($given)) 3 9 12
65 9 ▶ return 1 if $ppr->match($given);
Branch: 1 branch
BranchTrueFalseTotal
if $ppr->match($given) 3 6 9
66 19 };
67 19 ▶ if ($ok) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ok) 6 13 19
68 6 $self->update_password($given);
69 6 return 1;
70 }
71  
72 13 ▶ $ok = try {
Subroutine __ANON__: called CC=1 SCAR=0.0
73 13 my $ppr = Authen::Passphrase->from_rfc2307($want);
74 8 return $ppr->match($given);
75 13 };
76 13 ▶ return 0 unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 7 6 13
77 6 $self->update_password($given);
78 6 return 1;
79 }
80  
81 0 ▶sub _build_hashing_default {
Subroutine _build_hashing_default: not called CC=1 SCAR=6.9
82 0 my $self = shift;
83 0 warn "DEPRECATION: Please supply a hashing default";
84 0 return 'sha512';
85 }
86  
87 21 ▶sub prehash_password {
Subroutine prehash_password: called CC=2 SCAR=6.9
Pod documented
88 21 my $self = shift;
89 21 my $pass = shift;
90  
91 21 ▶ if ($self->hashing eq 'none') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hashing eq "none") 3 18 21
92 3 return $pass;
93 }
94  
95 18 my $sha = Digest::SHA->new($self->hashing);
96 18 $sha->add($pass);
97 18 return $sha->b64digest;
98 }
99  
100 12 ▶sub _prehash_password {
Subroutine _prehash_password: called CC=1 SCAR=0.0
101 12 my $self = shift;
102 12 my $pass = shift;
103  
104 12 my $sha = Digest::SHA->new('sha512');
105 12 $sha->add($pass);
106 12 return $sha->b64digest;
107 }
108  
109 0 ▶sub hash_password {
Subroutine hash_password: not called CC=1 SCAR=6.9
Pod documented
110 0 my $self = shift;
111 0 warn "DEPRECATION: Please use prehash_password instead";
112 0 return $self->prehash_password(@_);
113 }
114  
115 12 ▶sub update_password {
Subroutine update_password: called CC=2 SCAR=6.9
Pod documented
116 12 my ($self, $given) = @_;
117 12 ▶ return 0 unless $self->has_update_method;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_update_method 9 3 12
118 3 $self->update_method->($self->crypt_password($given));
119 3 return 1;
120 }
121  
122 7 1;
123  
124 __END__
↑ Summary OWASP/Argon2.pm »