| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package OpenPlugin::Authenticate::DBI; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # $Id: DBI.pm,v 1.11 2003/04/03 01:51:24 andreychek Exp $ | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 1264 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 61 |  | 
| 6 | 1 |  |  | 1 |  | 706 | use OpenPlugin::Authenticate(); | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 7 | 1 |  |  | 1 |  | 7 | use base          qw( OpenPlugin::Authenticate ); | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 371 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | #use OpenPlugin::Authenticate(); | 
| 10 |  |  |  |  |  |  | #$OpenPlugin::Authenticate::DBI::ISA = qw( OpenPlugin::Authenticate ); | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | $OpenPlugin::Authenticate::DBI::VERSION = sprintf("%d.%02d", q$Revision: 1.11 $ =~ /(\d+)\.(\d+)/); | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub authenticate { | 
| 15 | 0 |  |  | 0 | 0 |  | my ($self, $args) = @_; | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 0 | 0 |  |  |  |  | return 0 if $args->{username} eq ""; | 
| 18 |  |  |  |  |  |  |  | 
| 19 | 0 |  |  |  |  |  | my $ret = 0; | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 0 |  | 0 |  |  |  | $args->{username_field} ||= "username"; | 
| 22 | 0 |  | 0 |  |  |  | $args->{password_field} ||= "password"; | 
| 23 | 0 |  | 0 |  |  |  | $args->{table}          ||= ""; | 
| 24 |  |  |  |  |  |  |  | 
| 25 | 0 | 0 | 0 |  |  |  | $self->OP->exception->throw ("No datasource or table argument given" ) | 
| 26 |  |  |  |  |  |  | unless (($args->{datasource}) && ($args->{table})); | 
| 27 |  |  |  |  |  |  |  | 
| 28 | 0 |  |  |  |  |  | $self->OP->log->info( "Authenticating $args->{username}"); | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 0 |  |  |  |  |  | my $dbh = eval { $self->OP->datasource->connect( $args->{datasource} ); }; | 
|  | 0 |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 0 | 0 |  |  |  |  | if ( $@ ) { | 
| 33 | 0 |  |  |  |  |  | $self->OP->exception->throw("Connection Error: $@\n"); | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 | 0 |  |  |  |  |  | my $sth = $dbh->prepare("SELECT $args->{username_field} FROM " . | 
| 37 |  |  |  |  |  |  | "$args->{table} where $args->{username_field} = " . | 
| 38 |  |  |  |  |  |  | "'$args->{username}' and "     . | 
| 39 |  |  |  |  |  |  | "$args->{password_field} = " . | 
| 40 |  |  |  |  |  |  | "'$args->{password}'"); | 
| 41 | 0 |  |  |  |  |  | $sth->execute; | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 0 |  |  |  |  |  | my $row = $sth->fetchrow_hashref; | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 | 0 |  |  |  |  | $ret = 1 if $row->{ $args->{username_field} } eq $args->{username}; | 
| 46 |  |  |  |  |  |  |  | 
| 47 | 0 |  |  |  |  |  | $self->OP->log->info( "Authenticate returned ($ret)"); | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 0 |  |  |  |  |  | return($ret); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | 1; | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | __END__ |