Authen-Simple-CDBI-0.2/ 0040755 0000765 0000765 00000000000 10362440250 014357 5 ustar chansen chansen Authen-Simple-CDBI-0.2/Build.PL 0100644 0000765 0000765 00000000537 10362440250 015655 0 ustar chansen chansen use strict;
use Module::Build;
my $build = Module::Build->new(
license => 'perl',
module_name => 'Authen::Simple::CDBI',
requires => {
'Authen::Simple' => 0.3,
'Class::DBI' => 0.96
},
create_makefile_pl => 'traditional',
create_readme => 1
);
$build->create_build_script;
Authen-Simple-CDBI-0.2/Changes 0100644 0000765 0000765 00000000313 10362440250 015644 0 ustar chansen chansen Revision history for Perl extension Authen::Simple::CDBI
0.2 2006-01-15 00:00
- Verify class and columns at construction time.
- Fixed spelling errors.
0.1 2006-01-13 00:00
- First release
Authen-Simple-CDBI-0.2/lib/ 0040755 0000765 0000765 00000000000 10362440250 015125 5 ustar chansen chansen Authen-Simple-CDBI-0.2/lib/Authen/ 0040755 0000765 0000765 00000000000 10362440250 016351 5 ustar chansen chansen Authen-Simple-CDBI-0.2/lib/Authen/Simple/ 0040755 0000765 0000765 00000000000 10362440250 017602 5 ustar chansen chansen Authen-Simple-CDBI-0.2/lib/Authen/Simple/CDBI.pm 0100644 0000765 0000765 00000007465 10362440250 020652 0 ustar chansen chansen package Authen::Simple::CDBI;
use strict;
use warnings;
use base 'Authen::Simple::Adapter';
use Carp qw[];
use Params::Validate qw[];
our $VERSION = 0.2;
__PACKAGE__->options({
class => {
type => Params::Validate::SCALAR,
optional => 0
},
username => {
type => Params::Validate::SCALAR,
default => 'username',
optional => 1
},
password => {
type => Params::Validate::SCALAR,
default => 'password',
optional => 1
}
});
sub init {
my ( $self, $params ) = @_;
my $class = $params->{class};
my $username = $params->{username};
my $password = $params->{password};
unless ( eval "require $class;" ) {
Carp::croak( qq/Failed to require class '$class'. Reason: '$@'/ );
}
unless ( $class->isa('Class::DBI') ) {
Carp::croak( qq/Class '$class' is not a subclass of 'Class::DBI'./ );
}
unless ( $class->find_column($username) ) {
Carp::croak( qq/Class '$class' does not have a username column named '$username'/ );
}
unless ( $class->find_column($password) ) {
Carp::croak( qq/Class '$class' does not have a password column named '$password'/ );
}
return $self->SUPER::init($params);
}
sub check {
my ( $self, $username, $password ) = @_;
my ( $class, $user, $encrypted ) = ( $self->class, undef, undef );
unless ( $user = $class->retrieve( $self->username => $username ) ) {
$self->log->debug( qq/User '$username' was not found with class '$class'./ )
if $self->log;
return 0;
}
$encrypted = $user->get( $self->password );
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' with class '$class'./ )
if $self->log;
return 1;
}
1;
__END__
=head1 NAME
Authen::Simple::CDBI - Simple Class::DBI authentication
=head1 SYNOPSIS
use Authen::Simple::CDBI;
my $cdbi = Authen::Simple::CDBI->new(
class => 'MyApp::Model::User'
);
if ( $cdbi->authenticate( $username, $password ) ) {
# successfull authentication
}
# or as a mod_perl Authen handler
PerlModule Authen::Simple::Apache
PerlModule Authen::Simple::CDBI
PerlSetVar AuthenSimpleDBI_class "MyApp::Model::User"
PerlAuthenHandler Authen::Simple::CDBI
AuthType Basic
AuthName "Protected Area"
Require valid-user
=head1 DESCRIPTION
Class::DBI authentication.
=head1 METHODS
=over 4
=item * new
This method takes a hash of parameters. The following options are
valid:
=over 8
=item * class
Class::DBI subclass. Required.
class => 'MyApp::Model::User'
=item * username
Name of C column. Defaults to C.
username => 'username'
=item * password
Name of C column. Defaults to C.
password => 'password'
=item * log
Any object that supports C, C, C and C.
log => Log::Log4perl->get_logger('Authen::Simple::CDBI')
=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-CDBI-0.2/Makefile.PL 0100644 0000765 0000765 00000000702 10362440250 016325 0 ustar chansen chansen # Note: this file was auto-generated by Module::Build::Compat version 0.03
use ExtUtils::MakeMaker;
WriteMakefile
(
'NAME' => 'Authen::Simple::CDBI',
'VERSION_FROM' => 'lib/Authen/Simple/CDBI.pm',
'PREREQ_PM' => {
'Authen::Simple' => '0.3',
'Class::DBI' => '0.96'
},
'INSTALLDIRS' => 'site',
'PL_FILES' => {}
)
;
Authen-Simple-CDBI-0.2/MANIFEST 0100644 0000765 0000765 00000000315 10362440250 015504 0 ustar chansen chansen Build.PL
Changes
lib/Authen/Simple/CDBI.pm
Makefile.PL
MANIFEST This list of files
README
t/01use.t
t/02pod.t
t/03podcoverage.t
t/04basic.t
t/lib/MyClass.pm
t/var/database.db
t/var/database.sql
META.yml
Authen-Simple-CDBI-0.2/META.yml 0100644 0000765 0000765 00000000511 10362440250 015622 0 ustar chansen chansen ---
name: Authen-Simple-CDBI
version: 0.2
author:
- 'Christian Hansen C'
abstract: Simple Class::DBI authentication
license: perl
requires:
Authen::Simple: 0.3
Class::DBI: 0.96
provides:
Authen::Simple::CDBI:
file: lib/Authen/Simple/CDBI.pm
version: 0.2
generated_by: Module::Build version 0.2611
Authen-Simple-CDBI-0.2/README 0100644 0000765 0000765 00000003366 10362440250 015244 0 ustar chansen chansen NAME
Authen::Simple::CDBI - Simple Class::DBI authentication
SYNOPSIS
use Authen::Simple::CDBI;
my $cdbi = Authen::Simple::CDBI->new(
class => 'MyApp::Model::User'
);
if ( $cdbi->authenticate( $username, $password ) ) {
# successfull authentication
}
# or as a mod_perl Authen handler
PerlModule Authen::Simple::Apache
PerlModule Authen::Simple::CDBI
PerlSetVar AuthenSimpleDBI_class "MyApp::Model::User"
PerlAuthenHandler Authen::Simple::CDBI
AuthType Basic
AuthName "Protected Area"
Require valid-user
DESCRIPTION
Class::DBI authentication.
METHODS
* new
This method takes a hash of parameters. The following options are
valid:
* class Class::DBI subclass. Required.
class => 'MyApp::Model::User'
* username
Name of "username" column. Defaults to "username".
username => 'username'
* password
Name of "password" column. Defaults to "password".
password => 'password'
* log Any object that supports "debug", "info", "error" and
"warn".
log => Log::Log4perl->get_logger('Authen::Simple::CDBI')
* authenticate( $username, $password )
Returns true on success and false on failure.
SEE ALSO
Authen::Simple.
Authen::Simple::Password.
Class::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-CDBI-0.2/t/ 0040755 0000765 0000765 00000000000 10362440250 014622 5 ustar chansen chansen Authen-Simple-CDBI-0.2/t/01use.t 0100644 0000765 0000765 00000000074 10362440250 015742 0 ustar chansen chansen use Test::More tests => 1;
use_ok('Authen::Simple::CDBI');
Authen-Simple-CDBI-0.2/t/02pod.t 0100644 0000765 0000765 00000000276 10362440250 015735 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-CDBI-0.2/t/03podcoverage.t 0100644 0000765 0000765 00000000372 10362440250 017447 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|init$/ ] } );
Authen-Simple-CDBI-0.2/t/04basic.t 0100644 0000765 0000765 00000002367 10362440250 016241 0 ustar chansen chansen #!perl
use strict;
use warnings;
use lib 't/lib';
use Test::More;
unless ( eval "use DBD::SQLite 1.0; 1;" ) {
plan skip_all => 'needs DBD::SQLite >= 1.0 for testing';
}
plan tests => 11;
use_ok('Authen::Simple::CDBI');
use_ok('MyClass');
my $cdbi = Authen::Simple::CDBI->new(
class => 'MyClass',
username => 'username',
password => 'password'
);
ok( $cdbi, 'Got instance' );
ok( $cdbi->authenticate( 'crypt', 'crypt' ), 'Successfully authenticated using crypt() with Traditional DES' );
ok( $cdbi->authenticate( 'md5', 'md5' ), 'Successfully authenticated using $1$' );
ok( $cdbi->authenticate( 'plain', 'plain' ), 'Successfully authenticated using plain' );
ok( $cdbi->authenticate( 'sha', 'sha' ), 'Successfully authenticated using {SHA}' );
ok( $cdbi->authenticate( 'smd5', 'smd5' ), 'Successfully authenticated using {SMD5}' );
ok( $cdbi->authenticate( 'sha-1 hex', 'sha-1 hex' ), 'Successfully authenticated using SHA-1 hex' );
ok( $cdbi->authenticate( 'sha-1 base64', 'sha-1 base64' ), 'Successfully authenticated using SHA-1 Base64' );
ok( ! $cdbi->authenticate( 'bogus', 'bogus' ), 'Failed to authenticate user bogus' );
Authen-Simple-CDBI-0.2/t/lib/ 0040755 0000765 0000765 00000000000 10362440250 015370 5 ustar chansen chansen Authen-Simple-CDBI-0.2/t/lib/MyClass.pm 0100644 0000765 0000765 00000000413 10362440250 017274 0 ustar chansen chansen package MyClass;
use strict;
use warnings;
use base 'Class::DBI';
__PACKAGE__->table('users');
__PACKAGE__->columns( Primary => qw[username] );
__PACKAGE__->columns( Essential => qw[password] );
__PACKAGE__->connection('dbi:SQLite:dbname=t/var/database.db');
1;
Authen-Simple-CDBI-0.2/t/var/ 0040755 0000765 0000765 00000000000 10362440250 015412 5 ustar chansen chansen Authen-Simple-CDBI-0.2/t/var/database.db 0100644 0000765 0000765 00000010000 10362440250 017451 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-CDBI-0.2/t/var/database.sql 0100644 0000765 0000765 00000001364 10362440250 017700 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' );