line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Lazy::Authn; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1006
|
use strict; |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
37
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use CGI::Lazy::Globals; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
99
|
|
6
|
1
|
|
|
1
|
|
6
|
use Digest::MD5; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1030
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
9
|
|
|
|
|
|
|
sub activeField { |
10
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
return $self->{_activeField}; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
16
|
|
|
|
|
|
|
sub authenticate { |
17
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
18
|
|
|
|
|
|
|
|
19
|
0
|
|
|
|
|
|
my $extraFields = $self->extraFields; |
20
|
0
|
|
|
|
|
|
my @extraFields; |
21
|
|
|
|
|
|
|
my @binds; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $username = $self->q->param($self->userField); |
24
|
0
|
|
|
|
|
|
my $passwd = $self->q->param($self->passwdField); |
25
|
|
|
|
|
|
|
|
26
|
0
|
0
|
0
|
|
|
|
return unless $username && $passwd; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
$passwd = $self->passwdhash($username, $passwd); |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
push @binds, $username; |
31
|
0
|
|
|
|
|
|
push @binds, $passwd; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
#$self->q->util->debug->edump($passwd); |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
foreach my $webfield (keys %$extraFields) { |
36
|
0
|
|
|
|
|
|
push @extraFields, $extraFields->{$webfield}; |
37
|
0
|
|
|
|
|
|
push @binds, $self->q->param($webfield); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $query = 'select * from '. $self->table. ' where '. $self->userField . ' = ? and '. $self->passwdField . ' = ? and '. $self->activeField .' = 1 '; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
foreach (@extraFields) { |
43
|
0
|
|
|
|
|
|
$query .= " and $_ = ?"; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $result = $self->q->db->gethashlist($query, @binds); |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if ($result->[0]) { |
49
|
0
|
|
|
|
|
|
$self->q->session->data->authn({username => $username, authenticated => 1, id => $result->[0]->{$self->primarykey}}); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return 1; |
52
|
|
|
|
|
|
|
} else { |
53
|
0
|
|
|
|
|
|
return 0; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
58
|
|
|
|
|
|
|
sub check { |
59
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $session = $self->q->session; |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
0
|
|
|
|
if (!$session->expired && $session->data->authn && $session->data->authn->{username} && $session->data->authn->{authenticated}) { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return 1; |
65
|
|
|
|
|
|
|
} else { |
66
|
0
|
0
|
|
|
|
|
if ($self->authenticate) { |
67
|
0
|
|
|
|
|
|
return $self->authenticate; |
68
|
|
|
|
|
|
|
} else { |
69
|
0
|
|
|
|
|
|
return $self->redirectLogin; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
75
|
|
|
|
|
|
|
sub extraFields { |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $self->{_extraFields}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
82
|
|
|
|
|
|
|
sub q { |
83
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
return $self->{_q}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
89
|
|
|
|
|
|
|
sub new { |
90
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
91
|
0
|
|
|
|
|
|
my $q = shift; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
my $self = { |
94
|
|
|
|
|
|
|
_q => $q, |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
}; |
97
|
|
|
|
|
|
|
|
98
|
0
|
|
|
|
|
|
$self->{_table} = $q->plugin->authn->{table}; |
99
|
0
|
|
|
|
|
|
$self->{_template} = $q->plugin->authn->{template}; |
100
|
0
|
|
|
|
|
|
$self->{_primarykey} = $q->plugin->authn->{primarykey}; |
101
|
0
|
|
|
|
|
|
$self->{_salt} = $q->plugin->authn->{salt}; |
102
|
0
|
|
|
|
|
|
$self->{_extraFields} = $q->plugin->authn->{extraFields}; |
103
|
0
|
|
0
|
|
|
|
$self->{_userField} = $q->plugin->authn->{userField} || 'username'; |
104
|
0
|
|
0
|
|
|
|
$self->{_passwdField} = $q->plugin->authn->{passwdField} || $q->plugin->authn->{passwordField} || 'password'; |
105
|
0
|
|
0
|
|
|
|
$self->{_activeField} = $q->plugin->authn->{activeField} || 'active'; |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
bless $self, $class; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
die "Cannot use Authn without Session. Please enable Session plugin" unless $self->q->session; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $self; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
115
|
|
|
|
|
|
|
sub passwdField { |
116
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return $self->{_passwdField}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
122
|
|
|
|
|
|
|
sub passwdhash { |
123
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
124
|
0
|
|
|
|
|
|
my $username = shift; |
125
|
0
|
|
|
|
|
|
my $passwd = shift; |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
return Digest::MD5::md5_base64($username.$passwd.$self->salt); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
132
|
|
|
|
|
|
|
sub primarykey { |
133
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return $self->{_primarykey}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
139
|
|
|
|
|
|
|
sub redirectLogin { |
140
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my $tmplvars = {}; |
143
|
|
|
|
|
|
|
|
144
|
0
|
|
|
|
|
|
print $self->q->template($self->template)->process($tmplvars); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
return; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
150
|
|
|
|
|
|
|
sub salt { |
151
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
return $self->{_salt}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
157
|
|
|
|
|
|
|
sub table { |
158
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
159
|
|
|
|
|
|
|
|
160
|
0
|
|
|
|
|
|
return $self->{_table}; |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
164
|
|
|
|
|
|
|
sub template { |
165
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
166
|
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
return $self->{_template}; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
#---------------------------------------------------------------------------------------- |
171
|
|
|
|
|
|
|
sub userField { |
172
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
173
|
|
|
|
|
|
|
|
174
|
0
|
|
|
|
|
|
return $self->{_userField}; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1 |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |