| 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
Condition11%1/9
defined $user or $user = $c->request->param("login") || $c->request->param("user") || $c->request->param("username")
$c->request->param('login') || $c->request->param('user') || $c->request->param('username')
$c->request->param("login") or $c->request->param("user")
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition11%1/9
defined $password or $password = $c->request->param("password") || $c->request->param("passwd") || $c->request->param("pass")
$c->request->param('password') || $c->request->param('passwd') || $c->request->param('pass')
$c->request->param("password") or $c->request->param("passwd")
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')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | if $c->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 7 | ▶ | unless ( Scalar::Util::blessed($user) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($user) and $user->isa("Catalyst::Authentication::User")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | and $user->isa("Catalyst::Authentication::User") ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | ▶ | if ( my $user_obj = $c->get_user( $user, $password, @rest ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | if $c->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | ▶ | if ( $c->_check_password( $user, $password ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 5 | $c->set_authenticated($user); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 5 | ▶ | $c->log->debug("Successfully authenticated user '$user'.") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | if $c->debug; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1 | ▶ | $c->log->debug( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 || ''
MC/DC0%0/1
$user->password_pre_salt || ''
$user->password_pre_salt
Truth table50%1/2
A
A= $user->password_pre_salt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3 | $d->add($password); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 3 | ▶ | $d->add( $user->password_post_salt || '' ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$user->password_post_salt || ''
MC/DC0%0/1
$user->password_post_salt || ''
$user->password_post_salt
Truth table50%1/2
A
A= $user->password_post_salt
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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)
$computed eq $stored or unpack("H*", $computed) eq $stored or Catalyst::Authentication::Credential::Password::_secure_compare($b64computed, $stored)
$computed eq $stored or unpack("H*", $computed) eq $stored
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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||