Authen-Simple-DBI-0.2/ 0040755 0000765 0000765 00000000000 10362440343 014257 5 ustar chansen chansen Authen-Simple-DBI-0.2/Build.PL 0100644 0000765 0000765 00000000534 10362440343 015552 0 ustar chansen chansen use strict;
use Module::Build;
my $build = Module::Build->new(
license => 'perl',
module_name => 'Authen::Simple::DBI',
requires => {
'Authen::Simple' => 0.3,
'DBI' => 0,
},
create_makefile_pl => 'traditional',
create_readme => 1
);
$build->create_build_script;
Authen-Simple-DBI-0.2/Changes 0100644 0000765 0000765 00000000224 10362440343 015545 0 ustar chansen chansen Revision history for Perl extension Authen::Simple::DBI
0.2 2006-01-15 00:00
- Detect null passwords
0.1 2006-01-13 00:00
- First release
Authen-Simple-DBI-0.2/lib/ 0040755 0000765 0000765 00000000000 10362440343 015025 5 ustar chansen chansen Authen-Simple-DBI-0.2/lib/Authen/ 0040755 0000765 0000765 00000000000 10362440343 016251 5 ustar chansen chansen Authen-Simple-DBI-0.2/lib/Authen/Simple/ 0040755 0000765 0000765 00000000000 10362440343 017502 5 ustar chansen chansen Authen-Simple-DBI-0.2/lib/Authen/Simple/DBI.pm 0100644 0000765 0000765 00000012001 10362440343 020425 0 ustar chansen chansen package Authen::Simple::DBI;
use strict;
use warnings;
use base 'Authen::Simple::Adapter';
use DBI qw[SQL_CHAR];
use Params::Validate qw[];
our $VERSION = 0.2;
__PACKAGE__->options({
dsn => {
type => Params::Validate::SCALAR,
optional => 0
},
statement => {
type => Params::Validate::SCALAR,
optional => 0
},
username => {
type => Params::Validate::SCALAR,
optional => 1
},
password => {
type => Params::Validate::SCALAR,
optional => 1
},
attributes => { # undocumented for now
type => Params::Validate::HASHREF,
default => { ChopBlanks => 1, PrintError => 0, RaiseError => 0 },
optional => 1
}
});
sub check {
my ( $self, $username, $password ) = @_;
my ( $dsn, $dbh, $sth, $encrypted ) = ( $self->dsn, undef, undef, undef );
unless ( $dbh = DBI->connect_cached( $dsn, $self->username, $self->password, $self->attributes ) ) {
my $error = DBI->errstr;
$self->log->error( qq/Failed to connect to database using dsn '$dsn'. Reason: '$error'/ )
if $self->log;
return 0;
}
unless ( $sth = $dbh->prepare_cached( $self->statement ) ) {
my $error = $dbh->errstr;
my $statement = $self->statement;
$self->log->error( qq/Failed to prepare statement '$statement'. Reason: '$error'/ )
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 = ?"
PerlAuthenHandler Authen::Simple::DBI
AuthType Basic
AuthName "Protected Area"
Require valid-user
=head1 DESCRIPTION
DBI authentication.
=head1 METHODS
=over 4
=item * new
This method takes a hash of parameters. The following options are
valid:
=over 8
=item * dsn
Database Source Name. Required.
dsn => 'dbi:SQLite:dbname=database.db'
dsn => 'dbi:mysql:database=database;host=localhost;'
=item * statement
SQL statement. The statement must take a single string argument (username) and
return a single value (password). Required.
statement => 'SELECT password FROM users WHERE username = ?'
=item * username
Database username.
username => 'username'
=item * password
Database password.
password => 'secret'
=item * log
Any object that supports C, C, C and C.
log => Log::Log4perl->get_logger('Authen::Simple::DBI')
=back
=item * authenticate( $username, $password )
Returns true on success and false on failure.
=back
=head1 SEE ALSO
L.
L.
L.
=head1 AUTHOR
Christian Hansen C
=head1 COPYRIGHT
This program is free software, you can redistribute it and/or modify
it under the same terms as Perl itself.
=cut
Authen-Simple-DBI-0.2/Makefile.PL 0100644 0000765 0000765 00000000666 10362440343 016236 0 ustar chansen chansen # Note: this file was auto-generated by Module::Build::Compat version 0.03
use ExtUtils::MakeMaker;
WriteMakefile
(
'NAME' => 'Authen::Simple::DBI',
'VERSION_FROM' => 'lib/Authen/Simple/DBI.pm',
'PREREQ_PM' => {
'Authen::Simple' => '0.3',
'DBI' => '0'
},
'INSTALLDIRS' => 'site',
'PL_FILES' => {}
)
;
Authen-Simple-DBI-0.2/MANIFEST 0100644 0000765 0000765 00000000273 10362440343 015407 0 ustar chansen chansen Build.PL
Changes
lib/Authen/Simple/DBI.pm
Makefile.PL
MANIFEST This list of files
README
t/01use.t
t/02pod.t
t/03podcoverage.t
t/04basic.t
t/var/database.db
t/var/database.sql
META.yml
Authen-Simple-DBI-0.2/META.yml 0100644 0000765 0000765 00000000465 10362440343 015532 0 ustar chansen chansen ---
name: Authen-Simple-DBI
version: 0.2
author:
- 'Christian Hansen C'
abstract: Simple DBI authentication
license: perl
requires:
Authen::Simple: 0.3
DBI: 0
provides:
Authen::Simple::DBI:
file: lib/Authen/Simple/DBI.pm
version: 0.2
generated_by: Module::Build version 0.2611
Authen-Simple-DBI-0.2/README 0100644 0000765 0000765 00000004340 10362440343 015135 0 ustar chansen chansen NAME
Authen::Simple::DBI - Simple DBI authentication
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 = ?"
PerlAuthenHandler Authen::Simple::DBI
AuthType Basic
AuthName "Protected Area"
Require valid-user
DESCRIPTION
DBI authentication.
METHODS
* new
This method takes a hash of parameters. The following options are
valid:
* dsn Database Source Name. Required.
dsn => 'dbi:SQLite:dbname=database.db'
dsn => 'dbi:mysql:database=database;host=localhost;'
* statement
SQL statement. The statement must take a single string
argument (username) and return a single value (password).
Required.
statement => 'SELECT password FROM users WHERE username = ?'
* username
Database username.
username => 'username'
* password
Database password.
password => 'secret'
* log Any object that supports "debug", "info", "error" and
"warn".
log => Log::Log4perl->get_logger('Authen::Simple::DBI')
* authenticate( $username, $password )
Returns true on success and false on failure.
SEE ALSO
Authen::Simple.
Authen::Simple::Password.
DBI.
AUTHOR
Christian Hansen "ch@ngmedia.com"
COPYRIGHT
This program is free software, you can redistribute it and/or modify it
under the same terms as Perl itself.
Authen-Simple-DBI-0.2/t/ 0040755 0000765 0000765 00000000000 10362440343 014522 5 ustar chansen chansen Authen-Simple-DBI-0.2/t/01use.t 0100644 0000765 0000765 00000000073 10362440343 015641 0 ustar chansen chansen use Test::More tests => 1;
use_ok('Authen::Simple::DBI');
Authen-Simple-DBI-0.2/t/02pod.t 0100644 0000765 0000765 00000000276 10362440343 015635 0 ustar chansen chansen use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => 'Test::Pod 1.14 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_files_ok();
Authen-Simple-DBI-0.2/t/03podcoverage.t 0100644 0000765 0000765 00000000365 10362440343 017351 0 ustar chansen chansen use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => 'Test::Pod::Coverage 1.04 required' if $@;
plan skip_all => 'set TEST_POD to enable this test' unless $ENV{TEST_POD};
all_pod_coverage_ok( { trustme => [ qr/^check$/ ] } );
Authen-Simple-DBI-0.2/t/04basic.t 0100644 0000765 0000765 00000002356 10362440343 016137 0 ustar chansen chansen #!perl
use strict;
use warnings;
use Test::More;
unless ( eval "use DBD::SQLite 1.0; 1;" ) {
plan skip_all => 'needs DBD::SQLite >= 1.0 for testing';
}
plan tests => 10;
use_ok('Authen::Simple::DBI');
my $dbi = Authen::Simple::DBI->new(
dsn => 'dbi:SQLite:dbname=t/var/database.db',
statement => 'SELECT password FROM users WHERE username = ?'
);
ok( $dbi, 'Got instance' );
ok( $dbi->authenticate( 'crypt', 'crypt' ), 'Successfully authenticated using crypt() with Traditional DES' );
ok( $dbi->authenticate( 'md5', 'md5' ), 'Successfully authenticated using $1$' );
ok( $dbi->authenticate( 'plain', 'plain' ), 'Successfully authenticated using plain' );
ok( $dbi->authenticate( 'sha', 'sha' ), 'Successfully authenticated using {SHA}' );
ok( $dbi->authenticate( 'smd5', 'smd5' ), 'Successfully authenticated using {SMD5}' );
ok( $dbi->authenticate( 'sha-1 hex', 'sha-1 hex' ), 'Successfully authenticated using SHA-1 hex' );
ok( $dbi->authenticate( 'sha-1 base64', 'sha-1 base64' ), 'Successfully authenticated using SHA-1 Base64' );
ok( ! $dbi->authenticate( 'bogus', 'bogus' ), 'Failed to authenticate user bogus' );
Authen-Simple-DBI-0.2/t/var/ 0040755 0000765 0000765 00000000000 10362440343 015312 5 ustar chansen chansen Authen-Simple-DBI-0.2/t/var/database.db 0100644 0000765 0000765 00000010000 10362440343 017351 0 ustar chansen chansen SQLite format 3 @
5 [/indexix_users_usernameusersCREATE UNIQUE INDEX ix_users_username ON users (username)tableusersusersCREATE TABLE users (
username CHAR(20) NOT NULL,
password VARCHAR(64) NOT NULL,
CONSTRAINT pk_users PRIMARY KEY (username)
))= indexsqlite_autoindex_users_1users
\0 4]sha-1 hexfc1e1866232bfebfac8a8db8f0225a5166fa1a99*%Csha-1 base644zJ0YGPiLDff9wRf61PVIsC5Nms'Osha{SHA}2PRZAyDhNDqRW2OUFwZQqPNdaSY=)Qsmd5{SMD5}eVWRi45+VqS2Xw4bJPN+SrGfpVg=(Qmd5$1$NRe32ijZ$THIS7aDH.e093oDOGD10M/'cryptlk9Mh5KHGjAaM
plainplain
sha-1 hex%sha-1 base64shasmd5md5 crypt plain
sha-1 hex%sha-1 base64shasmd5md5 crypt plainAuthen-Simple-DBI-0.2/t/var/database.sql 0100644 0000765 0000765 00000001364 10362440343 017600 0 ustar chansen chansen CREATE TABLE users (
username CHAR(20) NOT NULL,
password VARCHAR(64) NOT NULL,
CONSTRAINT pk_users PRIMARY KEY (username)
);
INSERT INTO users VALUES ( 'plain', 'plain' );
INSERT INTO users VALUES ( 'crypt', 'lk9Mh5KHGjAaM' );
INSERT INTO users VALUES ( 'md5', '$1$NRe32ijZ$THIS7aDH.e093oDOGD10M/' );
INSERT INTO users VALUES ( 'smd5', '{SMD5}eVWRi45+VqS2Xw4bJPN+SrGfpVg=' );
INSERT INTO users VALUES ( 'sha', '{SHA}2PRZAyDhNDqRW2OUFwZQqPNdaSY=' );
INSERT INTO users VALUES ( 'sha-1 base64', '4zJ0YGPiLDff9wRf61PVIsC5Nms' );
INSERT INTO users VALUES ( 'sha-1 hex', 'fc1e1866232bfebfac8a8db8f0225a5166fa1a99' );