Authen-Simple-CDBI-0.2/0040755000076500007650000000000010362440250014357 5ustar chansenchansenAuthen-Simple-CDBI-0.2/Build.PL0100644000076500007650000000053710362440250015655 0ustar chansenchansenuse 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/Changes0100644000076500007650000000031310362440250015644 0ustar chansenchansenRevision 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/0040755000076500007650000000000010362440250015125 5ustar chansenchansenAuthen-Simple-CDBI-0.2/lib/Authen/0040755000076500007650000000000010362440250016351 5ustar chansenchansenAuthen-Simple-CDBI-0.2/lib/Authen/Simple/0040755000076500007650000000000010362440250017602 5ustar chansenchansenAuthen-Simple-CDBI-0.2/lib/Authen/Simple/CDBI.pm0100644000076500007650000000746510362440250020652 0ustar chansenchansenpackage 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.PL0100644000076500007650000000070210362440250016325 0ustar chansenchansen# 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/MANIFEST0100644000076500007650000000031510362440250015504 0ustar chansenchansenBuild.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.yml0100644000076500007650000000051110362440250015622 0ustar chansenchansen--- 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/README0100644000076500007650000000336610362440250015244 0ustar chansenchansenNAME 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/0040755000076500007650000000000010362440250014622 5ustar chansenchansenAuthen-Simple-CDBI-0.2/t/01use.t0100644000076500007650000000007410362440250015742 0ustar chansenchansenuse Test::More tests => 1; use_ok('Authen::Simple::CDBI'); Authen-Simple-CDBI-0.2/t/02pod.t0100644000076500007650000000027610362440250015735 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-CDBI-0.2/t/03podcoverage.t0100644000076500007650000000037210362440250017447 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|init$/ ] } ); Authen-Simple-CDBI-0.2/t/04basic.t0100644000076500007650000000236710362440250016241 0ustar chansenchansen#!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/0040755000076500007650000000000010362440250015370 5ustar chansenchansenAuthen-Simple-CDBI-0.2/t/lib/MyClass.pm0100644000076500007650000000041310362440250017274 0ustar chansenchansenpackage 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/0040755000076500007650000000000010362440250015412 5ustar chansenchansenAuthen-Simple-CDBI-0.2/t/var/database.db0100644000076500007650000001000010362440250017451 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-CDBI-0.2/t/var/database.sql0100644000076500007650000000136410362440250017700 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' );