Plugin/Authentication/Credential/Password.pm

filter: Statementstmt 78.7% 37 / 47 Branchbran 50.0% 17 / 34 Conditioncond 35.2% 12 / 34 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 52.5% 72 / 137 CC 30 SCAR 40.1
CC
30
Cov
57%
login
91.6
_check_password
16.8
BEGIN
1.0
CRAP 55.0
↑ Summary Authentication/Credential/Password.pm »
1 package Catalyst::Plugin::Authentication::Credential::Password;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Catalyst::Authentication::Credential::Password ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 ## BACKWARDS COMPATIBILITY - all subs below here are deprecated
9 ## They are here for compatibility with older modules that use / inherit from C::P::A::Password
10 ## login()'s existance relies rather heavily on the fact that only Credential::Password
11 ## is being used as a credential. This may not be the case. This is only here
12 ## for backward compatibility. It will go away in a future version
13 ## login should not be used in new applications.
14  
15 7 ▶sub login {
Subroutine login: called CC=18 SCAR=45.2
Pod documented
16 7 my ( $c, $user, $password, @rest ) = @_;
17  
18 7 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $user or $user = $c->request->param("login") || $c->request->param("user") || $c->request->param("username")) 0 7 7
Condition11%1/9
defined $user or $user = $c->request->param("login") || $c->request->param("user") || $c->request->param("username")
l!l&&r!l&&!r
700
$c->request->param('login') || $c->request->param('user') || $c->request->param('username')
l!l&&r!l&&!r
000
$c->request->param("login") or $c->request->param("user")
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $user or $user = $c->request->param("login") || $c->request->param("user") || $c->request->param("username")
defined $user $c->request->param("login") $c->request->param("user") $c->request->param('username')
Truth table20%1/5
A or B or C || D
A= defined $userB= $c->request->param("login")C= $c->request->param("user")D= $c->request->param('username')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
19 defined($user)
20 or
21 $user = $c->request->param("login")
22 || $c->request->param("user")
23 || $c->request->param("username")
24 ) {
25 0 ▶ $c->log->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 0 0
26 "Can't login a user without a user object or user ID param")
27 if $c->debug;
28 0 return;
29 }
30  
31 7 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $password or $password = $c->request->param("password") || $c->request->param("passwd") || $c->request->param("pass")) 0 7 7
Condition11%1/9
defined $password or $password = $c->request->param("password") || $c->request->param("passwd") || $c->request->param("pass")
l!l&&r!l&&!r
700
$c->request->param('password') || $c->request->param('passwd') || $c->request->param('pass')
l!l&&r!l&&!r
000
$c->request->param("password") or $c->request->param("passwd")
l!l&&r!l&&!r
000
MC/DC0%0/4
defined $password or $password = $c->request->param("password") || $c->request->param("passwd") || $c->request->param("pass")
defined $password $c->request->param("password") $c->request->param("passwd") $c->request->param('pass')
Truth table20%1/5
A or B or C || D
A= defined $passwordB= $c->request->param("password")C= $c->request->param("passwd")D= $c->request->param('pass')
ABCDresult
1XXX1
01XX1
001X1
00011
00000
32 defined($password)
33 or
34 $password = $c->request->param("password")
35 || $c->request->param("passwd")
36 || $c->request->param("pass")
37 ) {
38 0 ▶ $c->log->debug("Can't login a user without a password")
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 0 0
39 if $c->debug;
40 0 return;
41 }
42  
43 7 ▶ unless ( Scalar::Util::blessed($user)
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($user) and $user->isa("Catalyst::Authentication::User")) 7 0 7
Condition33%1/3
builtin::blessed($user) and $user->isa("Catalyst::Authentication::User")
!ll&&!rl&&r
700
MC/DC0%0/2
builtin::blessed($user) and $user->isa("Catalyst::Authentication::User")
builtin::blessed($user) $user->isa("Catalyst::Authentication::User")
Truth table33%1/3
A and B
A= builtin::blessed($user)B= $user->isa("Catalyst::Authentication::User")
ABresult
0X0
100
111
44 and $user->isa("Catalyst::Authentication::User") )
45 {
46 7 ▶ if ( my $user_obj = $c->get_user( $user, $password, @rest ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $user_obj = $c->get_user($user, $password, @rest)) { } 7 0 7
47 7 $user = $user_obj;
48 }
49 else {
50 0 ▶ $c->log->debug("User '$user' doesn't exist in the default store")
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 0 0
51 if $c->debug;
52 0 return;
53 }
54 }
55  
56 7 ▶ if ( $c->_check_password( $user, $password ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->_check_password($user, $password)) { } 5 1 6
57 5 $c->set_authenticated($user);
58 5 ▶ $c->log->debug("Successfully authenticated user '$user'.")
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 5 5
59 if $c->debug;
60 5 return 1;
61 }
62 else {
63 1 ▶ $c->log->debug(
Branch: 1 branch
BranchTrueFalseTotal
if $c->debug 0 1 1
64 "Failed to authenticate user '$user'. Reason: 'Incorrect password'")
65 if $c->debug;
66 1 return;
67 }
68  
69 }
70  
71 ## also deprecated. Here for compatibility with older credentials which do not inherit from C::P::A::Password
72 7 ▶sub _check_password {
Subroutine _check_password: called CC=13 SCAR=28.2
73 7 my ( $c, $user, $password ) = @_;
74  
75 7 ▶ if ( $user->supports(qw/password clear/) ) {
Branch: 5 branches
BranchTrueFalseTotal
if ($user->supports('password', 'clear')) { } 1 6 7
elsif ($user->supports('password', 'crypted')) { } 2 4 6
elsif ($user->supports('password', 'hashed')) { } 3 1 4
elsif ($user->supports('password', 'salted_hash')) { } 0 1 1
elsif ($user->supports('password', 'self_check')) { } 0 1 1
76 1 return Catalyst::Authentication::Credential::Password::_secure_compare( $user->password, $password );
77 }
78 elsif ( $user->supports(qw/password crypted/) ) {
79 2 my $crypted = $user->crypted_password;
80 2 ▶ return if not defined $crypted;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $crypted 0 2 2
81 2 return Catalyst::Authentication::Credential::Password::_secure_compare( $crypted, crypt( $password, $crypted ) );
82 }
83 elsif ( $user->supports(qw/password hashed/) ) {
84  
85 3 my $d = Digest->new( $user->hash_algorithm );
86 3 ▶ $d->add( $user->password_pre_salt || '' );
Condition50%1/2
$user->password_pre_salt || ''
l!l
03
MC/DC0%0/1
$user->password_pre_salt || ''
$user->password_pre_salt
Truth table50%1/2
A
A= $user->password_pre_salt
Aresult
11
00
87 3 $d->add($password);
88 3 ▶ $d->add( $user->password_post_salt || '' );
Condition50%1/2
$user->password_post_salt || ''
l!l
03
MC/DC0%0/1
$user->password_post_salt || ''
$user->password_post_salt
Truth table50%1/2
A
A= $user->password_post_salt
Aresult
11
00
89  
90 3 my $stored = $user->hashed_password;
91 3 my $computed = $d->clone()->digest;
92 3 my $b64computed = $d->clone()->b64digest;
93  
94 3 ▶ return ( ( $computed eq $stored )
Condition77%7/9
$computed eq $stored || unpack('H*', $computed) eq $stored || Catalyst::Authentication::Credential::Password::_secure_compare($b64computed, $stored) || Catalyst::Authentication::Credential::Password::_secure_compare($b64computed . '=', $stored)
l!l&&r!l&&!r
210
$computed eq $stored or unpack("H*", $computed) eq $stored or Catalyst::Authentication::Credential::Password::_secure_compare($b64computed, $stored)
l!l&&r!l&&!r
111
$computed eq $stored or unpack("H*", $computed) eq $stored
l!l&&r!l&&!r
102
MC/DC0%0/4
$computed eq $stored || unpack('H*', $computed) eq $stored || Catalyst::Authentication::Credential::Password::_secure_compare($b64computed, $stored) || Catalyst::Authentication::Credential::Password::_secure_compare($b64computed . '=', $stored)
$computed eq $stored unpack("H*", $computed) eq $stored Catalyst::Authentication::Credential::Password::_secure_compare($b64computed, $stored) Catalyst::Authentication::Credential::Password::_secure_compare($b64computed . '=', $stored)
Truth table60%3/5
A or B or C || D
A= $computed eq $storedB= unpack("H*", $computed) eq $storedC= Catalyst::Authentication::Credential::Password::_secure_compare($b64computed, $stored)D= Catalyst::Authentication::Credential::Password::_secure_compare($b64computed . '=', $stored)
ABCDresult
1XXX1
01XX1
001X1
00011
00000
95 || ( unpack( "H*", $computed ) eq $stored )
96 || Catalyst::Authentication::Credential::Password::_secure_compare( $b64computed, $stored)
97 || Catalyst::Authentication::Credential::Password::_secure_compare( $b64computed.'=', $stored) );
98 }
99 elsif ( $user->supports(qw/password salted_hash/) ) {
100 0 require Crypt::SaltedHash;
101  
102 0 ▶ my $salt_len =
Branch: 1 branch
BranchTrueFalseTotal
$user->can('password_salt_len') ? : 0 0 0
103 $user->can("password_salt_len") ? $user->password_salt_len : 0;
104  
105 0 return Crypt::SaltedHash->validate( $user->hashed_password, $password,
106 $salt_len );
107 }
108 elsif ( $user->supports(qw/password self_check/) ) {
109  
110 # while somewhat silly, this is to prevent code duplication
111 0 return $user->check_password($password);
112  
113 }
114 else {
115 1 Catalyst::Exception->throw(
116 "The user object $user does not support any "
117 . "known password authentication mechanism." );
118 }
119 }
120  
121 1 __PACKAGE__;
122  
123 __END__
↑ Summary Authentication/Credential/Password.pm »