Created
June 27, 2011 13:10
-
-
Save pjlsergeant/1048824 to your computer and use it in GitHub Desktop.
diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -rubw /tmp/Catalyst-Plugin-Authentication-0.10017//lib/Catalyst/Authentication/Credential/Password.pm ./lib/Catalyst/Authentication/Credential/Password.pm | |
--- /tmp/Catalyst-Plugin-Authentication-0.10017//lib/Catalyst/Authentication/Credential/Password.pm 2011-01-24 23:29:57.000000000 +0000 | |
+++ ./lib/Catalyst/Authentication/Credential/Password.pm 2011-06-27 09:01:01.000000000 +0100 | |
@@ -25,7 +25,7 @@ | |
$self->_config->{'password_hash_type'} ||= 'SHA-1'; | |
my $passwordtype = $self->_config->{'password_type'}; | |
- if (!grep /$passwordtype/, ('none', 'clear', 'hashed', 'salted_hash', 'crypted', 'self_check')) { | |
+ if (!grep /$passwordtype/, ('none', 'clear', 'hashed', 'salted_hash', 'crypted', 'self_check', 'custom')) { | |
Catalyst::Exception->throw(__PACKAGE__ . " used with unsupported password type: " . $self->_config->{'password_type'}); | |
} | |
return $self; | |
@@ -90,6 +90,16 @@ | |
|| ( unpack( "H*", $computed ) eq $storedpassword ) | |
|| ( $b64computed eq $storedpassword) | |
|| ( $b64computed.'=' eq $storedpassword) ); | |
+ } elsif ($self->_config->{'password_type'} eq 'custom') { | |
+ my $code = $self->_config->{'password_sub'}; | |
+ return unless $code && ref($code) eq ref(sub{}); | |
+ return $code->( | |
+ $self, { | |
+ user => $user, | |
+ password => $password, | |
+ storedpassword => $storedpassword | |
+ } | |
+ ); | |
} | |
} | |
} | |
@@ -227,6 +237,41 @@ | |
=back | |
+=item custom | |
+ | |
+The code-ref in C<password_sub> is executed, authenticating if it returns true. | |
+ | |
+=over 8 | |
+ | |
+=item password_sub | |
+ | |
+ # Simple plain-text example | |
+ password_sub => sub { | |
+ my ( $self, $data ) = @_; | |
+ return $data->{password} eq $data->{savedpassword}; | |
+ } | |
+ | |
+A code-ref. Will be passed two items on execution - the class (C<$self>) and a | |
+hashref containing at least: | |
+ | |
+=over 12 | |
+ | |
+=item user | |
+ | |
+A L<Catalyst::Authentication::User> object | |
+ | |
+=item password | |
+ | |
+The user-provided password | |
+ | |
+=item storedpassword | |
+ | |
+The password string we have on record for the user. | |
+ | |
+=back | |
+ | |
+=back | |
+ | |
=back | |
=back |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment