1 package Catalyst::Plugin::Authentication::Credential::Password;
6 use Catalyst::Authentication::Credential::Password ();
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.
16 my ( $c, $user, $password, @rest ) = @_;
21 $user = $c->request->param("login")
22 || $c->request->param("user")
23 || $c->request->param("username")
26 "Can't login a user without a user object or user ID param")
34 $password = $c->request->param("password")
35 || $c->request->param("passwd")
36 || $c->request->param("pass")
38 $c->log->debug("Can't login a user without a password")
43 unless ( Scalar::Util::blessed($user)
44 and $user->isa("Catalyst::Authentication::User") )
46 if ( my $user_obj = $c->get_user( $user, $password, @rest ) ) {
50 $c->log->debug("User '$user' doesn't exist in the default store")
56 if ( $c->_check_password( $user, $password ) ) {
57 $c->set_authenticated($user);
58 $c->log->debug("Successfully authenticated user '$user'.")
64 "Failed to authenticate user '$user'. Reason: 'Incorrect password'")
71 ## also deprecated. Here for compatibility with older credentials which do not inherit from C::P::A::Password
73 my ( $c, $user, $password ) = @_;
75 if ( $user->supports(qw/password clear/) ) {
76 return $user->password eq $password;
78 elsif ( $user->supports(qw/password crypted/) ) {
79 my $crypted = $user->crypted_password;
80 return $crypted eq crypt( $password, $crypted );
82 elsif ( $user->supports(qw/password hashed/) ) {
84 my $d = Digest->new( $user->hash_algorithm );
85 $d->add( $user->password_pre_salt || '' );
87 $d->add( $user->password_post_salt || '' );
89 my $stored = $user->hashed_password;
90 my $computed = $d->clone()->digest;
91 my $b64computed = $d->clone()->b64digest;
93 return ( ( $computed eq $stored )
94 || ( unpack( "H*", $computed ) eq $stored )
95 || ( $b64computed eq $stored)
96 || ( $b64computed.'=' eq $stored) );
98 elsif ( $user->supports(qw/password salted_hash/) ) {
99 require Crypt::SaltedHash;
102 $user->can("password_salt_len") ? $user->password_salt_len : 0;
104 return Crypt::SaltedHash->validate( $user->hashed_password, $password,
107 elsif ( $user->supports(qw/password self_check/) ) {
109 # while somewhat silly, this is to prevent code duplication
110 return $user->check_password($password);
114 Catalyst::Exception->throw(
115 "The user object $user does not support any "
116 . "known password authentication mechanism." );
128 Catalyst::Plugin::Authentication::Credential::Password - Compatibility shim
132 THIS IS A COMPATIBILITY SHIM. It allows old configurations of Catalyst
133 Authentication to work without code changes.
135 B<DO NOT USE IT IN ANY NEW CODE!>
137 Please see L<Catalyst::Authentication::Credential::Password> for more information.