Authen-Simple-DBI
view release on metacpan or search on metacpan
lib/Authen/Simple/DBI.pm view on Meta::CPAN
if $self->log;
return 0;
}
unless ( $sth->bind_param( 1, $username, SQL_CHAR ) ) {
my $error = $sth->errstr;
my $statement = $self->statement;
$self->log->error( qq/Failed to bind param '$username' to statement '$statement'. Reason: '$error'/ )
if $self->log;
return 0;
}
unless ( $sth->execute ) {
my $error = $sth->errstr;
my $statement = $self->statement;
$self->log->error( qq/Failed to execute statement '$statement'. Reason: '$error'/ )
if $self->log;
return 0;
}
unless ( $sth->bind_col( 1, \$encrypted ) ) {
my $error = $sth->errstr;
my $statement = $self->statement;
$self->log->error( qq/Failed to bind column. Reason: '$error'/ )
if $self->log;
return 0;
}
unless ( $sth->fetch ) {
my $statement = $self->statement;
$self->log->debug( qq/User '$username' was not found with statement '$statement'./ )
if $self->log;
return 0;
}
$sth->finish;
unless ( defined $encrypted && length $encrypted ) {
$self->log->debug( qq/Encrypted password for user '$username' is null./ )
if $self->log;
return 0;
}
unless ( $self->check_password( $password, $encrypted ) ) {
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ )
if $self->log;
return 0;
}
$self->log->debug( qq/Successfully authenticated user '$username'./ )
if $self->log;
return 1;
}
1;
__END__
=head1 NAME
Authen::Simple::DBI - Simple DBI authentication
=head1 SYNOPSIS
use Authen::Simple::DBI;
my $dbi = Authen::Simple::DBI->new(
dsn => 'dbi:SQLite:dbname=database.db',
statement => 'SELECT password FROM users WHERE username = ?'
);
if ( $dbi->authenticate( $username, $password ) ) {
# successfull authentication
}
# or as a mod_perl Authen handler
PerlModule Apache::DBI
PerlModule Authen::Simple::Apache
PerlModule Authen::Simple::DBI
PerlSetVar AuthenSimpleDBI_dsn "dbi:SQLite:dbname=database.db"
PerlSetVar AuthenSimpleDBI_statement "SELECT password FROM users WHERE username = ?"
<Location /protected>
PerlAuthenHandler Authen::Simple::DBI
AuthType Basic
AuthName "Protected Area"
Require valid-user
</Location>
=head1 DESCRIPTION
DBI authentication.
=head1 METHODS
=over 4
=item * new
This method takes a hash of parameters. The following options are
valid:
( run in 1.002 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )