| 1 | #!/usr/local/bin/perl5 | ||
| 2 | # | ||
| 3 | |||
| 4 | package CGI::Session::Authenticator::Backdoor; | ||
| 5 | |||
| 6 | use Carp; | ||
| 7 | |||
| 8 | my %_params = ( -password => '-password' ); | ||
| 9 | |||
| 10 | sub _param | ||
| 11 | { | ||
| 12 | my $self = shift; | ||
| 13 | if ( scalar @_ == 1 ) | ||
| 14 | { | ||
| 15 | my $field = shift; | ||
| 16 | |||
| 17 | # | ||
| 18 | my $slot = $_params{$field}; | ||
| 19 | croak "Programmer Error: $field is not a known parameter" unless defined $slot; | ||
| 20 | return $self->{$slot}; | ||
| 21 | } | ||
| 22 | else | ||
| 23 | { | ||
| 24 | while( my $field = shift ) | ||
| 25 | { | ||
| 26 | my $slot = $_params{$field}; | ||
| 27 | |||
| 28 | # | ||
| 29 | croak "Programmer Error: $field is not a known parameter" unless defined $slot; | ||
| 30 | $self->{$slot} = shift; | ||
| 31 | } | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | sub set { _param(shift,@_); } | ||
| 36 | |||
| 37 | sub new | ||
| 38 | { | ||
| 39 | my $type = shift; | ||
| 40 | my $self = {}; | ||
| 41 | bless $self, $type; | ||
| 42 | $self->set( @_ ); | ||
| 43 | return $self; | ||
| 44 | } | ||
| 45 | |||
| 46 | sub password { set( shift(), '-password', @_ ); } | ||
| 47 | |||
| 48 | sub authenticated | ||
| 49 | { | ||
| 50 | my ( $self, $params ) = @_; | ||
| 51 | my $password = $params->{-password}; | ||
| 52 | my $backdoor_password = $self->password; | ||
| 53 | return ( $password eq $backdoor_password ); | ||
| 54 | } | ||
| 55 | |||
| 56 | |||
| 57 | =item CGI::Session::Authenticator::Backdoor | ||
| 58 | |||
| 59 | Authenticator implementing a backdoor password. | ||
| 60 | |||
| 61 | $auth = new CGI::Session::Authenticator( -password => $password ); | ||
| 62 | |||
| 63 | if ( $auth->authenticated( $param ) ) { ...success... } | ||
| 64 | else { ...failure... } | ||
| 65 | |||
| 66 | Returns true if the users's password matches the -password parameter. | ||
| 67 | |||
| 68 | =item CGI::Session::Authenticator::authenticated | ||
| 69 | |||
| 70 | It accepts on argument which is a reference to a hash. This hash contains | ||
| 71 | variables which are used to attempt authentication. | ||
| 72 | |||
| 73 | The standard values which are used for comparison. The basic ones are | ||
| 74 | '-username' and '-password'. | ||
| 75 | |||
| 76 | It returns a true value if the user was successfully authenticated, and a | ||
| 77 | false value if the user was not successfully authenticated. | ||
| 78 | |||
| 79 | =cut | ||
| 80 | |||
| 81 | 1; |