Authen-Simple-DBI-0.2/0040755000076500007650000000000010362440343014257 5ustar chansenchansenAuthen-Simple-DBI-0.2/Build.PL0100644000076500007650000000053410362440343015552 0ustar chansenchansenuse 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/Changes0100644000076500007650000000022410362440343015545 0ustar chansenchansenRevision 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/0040755000076500007650000000000010362440343015025 5ustar chansenchansenAuthen-Simple-DBI-0.2/lib/Authen/0040755000076500007650000000000010362440343016251 5ustar chansenchansenAuthen-Simple-DBI-0.2/lib/Authen/Simple/0040755000076500007650000000000010362440343017502 5ustar chansenchansenAuthen-Simple-DBI-0.2/lib/Authen/Simple/DBI.pm0100644000076500007650000001200110362440343020425 0ustar chansenchansenpackage 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.PL0100644000076500007650000000066610362440343016236 0ustar chansenchansen# 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/MANIFEST0100644000076500007650000000027310362440343015407 0ustar chansenchansenBuild.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.yml0100644000076500007650000000046510362440343015532 0ustar chansenchansen--- 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/README0100644000076500007650000000434010362440343015135 0ustar chansenchansenNAME 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/0040755000076500007650000000000010362440343014522 5ustar chansenchansenAuthen-Simple-DBI-0.2/t/01use.t0100644000076500007650000000007310362440343015641 0ustar chansenchansenuse Test::More tests => 1; use_ok('Authen::Simple::DBI'); Authen-Simple-DBI-0.2/t/02pod.t0100644000076500007650000000027610362440343015635 0ustar chansenchansenuse 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.t0100644000076500007650000000036510362440343017351 0ustar chansenchansenuse 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.t0100644000076500007650000000235610362440343016137 0ustar chansenchansen#!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/0040755000076500007650000000000010362440343015312 5ustar chansenchansenAuthen-Simple-DBI-0.2/t/var/database.db0100644000076500007650000001000010362440343017351 0ustar chansenchansenSQLite 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 \04]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.sql0100644000076500007650000000136410362440343017600 0ustar chansenchansenCREATE 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' );