X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fp5-CGI-Ex;a=blobdiff_plain;f=lib%2FCGI%2FEx%2FAuth.pm;h=0c384949746fcc3936c321fc1185069a6997b81c;hp=337801cd6b4da37927eb23fd8c2a9198fd8e2c39;hb=6c57b3331d84010b9e2031f8e3c8937c3117e8fc;hpb=d710d6cd21be21c0ab2df3566c2bd61d9015cac6 diff --git a/lib/CGI/Ex/Auth.pm b/lib/CGI/Ex/Auth.pm index 337801c..0c38494 100644 --- a/lib/CGI/Ex/Auth.pm +++ b/lib/CGI/Ex/Auth.pm @@ -7,7 +7,7 @@ CGI::Ex::Auth - Handle logins nicely. =cut ###----------------------------------------------------------------### -# Copyright 2006 - Paul Seamons # +# Copyright 2007 - Paul Seamons # # Distributed under the Perl Artistic License without warranty # ###----------------------------------------------------------------### @@ -18,7 +18,7 @@ use MIME::Base64 qw(encode_base64 decode_base64); use Digest::MD5 qw(md5_hex); use CGI::Ex; -$VERSION = '2.04'; +$VERSION = '2.11'; ###----------------------------------------------------------------### @@ -484,7 +484,8 @@ sub generate_token { if ( (defined($data->{'use_plaintext'}) ? $data->{'use_plaintext'} : $self->use_plaintext) # ->use_plaintext is true if ->use_crypt is || (defined($data->{'use_crypt'}) && $data->{'use_crypt'}) || (defined($data->{'type'}) && $data->{'type'} eq 'crypt')) { - $token = $data->{'user'} .'/'. $data->{'real_pass'}; + my $pass = defined($data->{'test_pass'}) ? $data->{'test_pass'} : $data->{'real_pass'}; + $token = $data->{'user'} .'/'. $pass; ### all other types go to cram - secure_hash_cram, cram, plaintext and md5 } else { @@ -728,18 +729,38 @@ __END__ =head1 SYNOPSIS - ### authorize the user - my $auth = $self->get_valid_auth({ - get_pass_by_user => \&get_pass_by_user, - }); + use CGI::Ex::Auth; + ### authorize the user + my $auth = CGI::Ex::Auth->get_valid_auth({ + get_pass_by_user => \&get_pass_by_user, + }); - sub get_pass_by_user { - my $auth = shift; - my $user = shift; - my $pass = some_way_of_getting_password($user); - return $pass; - } + + sub get_pass_by_user { + my $auth = shift; + my $user = shift; + my $pass = some_way_of_getting_password($user); + return $pass; + } + + ### OR - if you are using a OO based CGI or Application + + sub require_authentication { + my $self = shift; + + return $self->{'auth'} = CGI::Ex::Auth->get_valid_auth({ + get_pass_by_user => sub { + my ($auth, $user) = @_; + return $self->get_pass($user); + }, + }); + } + + sub get_pass { + my ($self, $user) = @_; + return $self->loopup_and_cache_pass($user); + } =head1 DESCRIPTION @@ -1049,7 +1070,8 @@ are not enabled, it may return the md5 sum of the password. get_pass_by_user => sub { my ($auth_obj, $user) = @_; - return $some_obj->get_pass({user => $user}); + my $pass = $some_obj->get_pass({user => $user}); + return $pass; } Alternately, get_pass_by_user may return a hashref of data items that