| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Authen::Simple::CDBI; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
944
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
43
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
38
|
|
|
5
|
1
|
|
|
1
|
|
16
|
use base 'Authen::Simple::Adapter'; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1065
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
48810
|
use Carp qw[]; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
19
|
|
|
8
|
1
|
|
|
1
|
|
7
|
use Params::Validate qw[]; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
646
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = 0.2; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
__PACKAGE__->options({ |
|
13
|
|
|
|
|
|
|
class => { |
|
14
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
|
15
|
|
|
|
|
|
|
optional => 0 |
|
16
|
|
|
|
|
|
|
}, |
|
17
|
|
|
|
|
|
|
username => { |
|
18
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
|
19
|
|
|
|
|
|
|
default => 'username', |
|
20
|
|
|
|
|
|
|
optional => 1 |
|
21
|
|
|
|
|
|
|
}, |
|
22
|
|
|
|
|
|
|
password => { |
|
23
|
|
|
|
|
|
|
type => Params::Validate::SCALAR, |
|
24
|
|
|
|
|
|
|
default => 'password', |
|
25
|
|
|
|
|
|
|
optional => 1 |
|
26
|
|
|
|
|
|
|
} |
|
27
|
|
|
|
|
|
|
}); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub init { |
|
30
|
0
|
|
|
0
|
1
|
|
my ( $self, $params ) = @_; |
|
31
|
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $class = $params->{class}; |
|
33
|
0
|
|
|
|
|
|
my $username = $params->{username}; |
|
34
|
0
|
|
|
|
|
|
my $password = $params->{password}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
unless ( eval "require $class;" ) { |
|
37
|
0
|
|
|
|
|
|
Carp::croak( qq/Failed to require class '$class'. Reason: '$@'/ ); |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
0
|
0
|
|
|
|
|
unless ( $class->isa('Class::DBI') ) { |
|
41
|
0
|
|
|
|
|
|
Carp::croak( qq/Class '$class' is not a subclass of 'Class::DBI'./ ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
unless ( $class->find_column($username) ) { |
|
45
|
0
|
|
|
|
|
|
Carp::croak( qq/Class '$class' does not have a username column named '$username'/ ); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
unless ( $class->find_column($password) ) { |
|
49
|
0
|
|
|
|
|
|
Carp::croak( qq/Class '$class' does not have a password column named '$password'/ ); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
return $self->SUPER::init($params); |
|
53
|
|
|
|
|
|
|
} |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub check { |
|
56
|
0
|
|
|
0
|
1
|
|
my ( $self, $username, $password ) = @_; |
|
57
|
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my ( $class, $user, $encrypted ) = ( $self->class, undef, undef ); |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
unless ( $user = $class->retrieve( $self->username => $username ) ) { |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/User '$username' was not found with class '$class'./ ) |
|
63
|
|
|
|
|
|
|
if $self->log; |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return 0; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
$encrypted = $user->get( $self->password ); |
|
69
|
|
|
|
|
|
|
|
|
70
|
0
|
0
|
0
|
|
|
|
unless ( defined $encrypted && length $encrypted ) { |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Encrypted password for user '$username' is null./ ) |
|
73
|
|
|
|
|
|
|
if $self->log; |
|
74
|
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return 0; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
unless ( $self->check_password( $password, $encrypted ) ) { |
|
79
|
|
|
|
|
|
|
|
|
80
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Failed to authenticate user '$username'. Reason: 'Invalid credentials'/ ) |
|
81
|
|
|
|
|
|
|
if $self->log; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return 0; |
|
84
|
|
|
|
|
|
|
} |
|
85
|
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
$self->log->debug( qq/Successfully authenticated user '$username' with class '$class'./ ) |
|
87
|
|
|
|
|
|
|
if $self->log; |
|
88
|
|
|
|
|
|
|
|
|
89
|
0
|
|
|
|
|
|
return 1; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |