Lazy/Authn.pm

filter: Statementstmt 12.9% 10 / 77 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 17.6% 3 / 17 Podpod 14.2% 2 / 14 totaltotal 10.0% 15 / 149 CC 16 SCAR 31.9
CC
16
Cov
9%
authenticate
42.0
check
42.0
new
42.0
CRAP 24.4
« Lazy/Utility/Debug.pm ↑ Summary Lazy/Javascript.pm »
1 package CGI::Lazy::Authn;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 1 ▶use CGI::Lazy::Globals;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Digest::MD5;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 #----------------------------------------------------------------------------------------
9 0 ▶sub activeField {
Subroutine activeField: not called CC=1 SCAR=6.9
Pod undocumented
10 0 my $self = shift;
11  
12 0 return $self->{_activeField};
13 }
14  
15 #----------------------------------------------------------------------------------------
16 0 ▶sub authenticate {
Subroutine authenticate: not called CC=6 SCAR=37.4
Pod undocumented
17 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 ▶ return unless $username && $passwd;
Branch: 1 branch
BranchTrueFalseTotal
unless $username and $passwd 0 0 0
Condition0%0/3
$username and $passwd
!ll&&!rl&&r
000
MC/DC0%0/2
$username and $passwd
$username $passwd
Truth table0%0/3
A and B
A= $usernameB= $passwd
ABresult
0X0
100
111
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 ▶ if ($result->[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result->[0]) { } 0 0 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 0 ▶sub check {
Subroutine check: not called CC=6 SCAR=37.4
Pod documented
59 0 my $self = shift;
60  
61 0 my $session = $self->q->session;
62  
63 0 ▶ if (!$session->expired && $session->data->authn && $session->data->authn->{username} && $session->data->authn->{authenticated}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $session->expired and $session->data->authn and $session->data->authn->{'username'} and $session->data->authn->{'authenticated'}) { } 0 0 0
Condition0%0/9
not $session->expired and $session->data->authn and $session->data->authn->{"username"} and $session->data->authn->{"authenticated"}
!ll&&!rl&&r
000
not $session->expired and $session->data->authn and $session->data->authn->{"username"}
!ll&&!rl&&r
000
not $session->expired and $session->data->authn
!ll&&!rl&&r
000
MC/DC0%0/4
not $session->expired and $session->data->authn and $session->data->authn->{"username"} and $session->data->authn->{"authenticated"}
not $session->expired $session->data->authn $session->data->authn->{"username"} $session->data->authn->{"authenticated"}
Truth table0%0/5
not(A) and B and C and D
A= not $session->expiredB= $session->data->authnC= $session->data->authn->{"username"}D= $session->data->authn->{"authenticated"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
64 0 return 1;
65 } else {
66 0 ▶ if ($self->authenticate) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->authenticate) { } 0 0 0
67 0 return $self->authenticate;
68 } else {
69 0 return $self->redirectLogin;
70 }
71 }
72 }
73  
74 #----------------------------------------------------------------------------------------
75 0 ▶sub extraFields {
Subroutine extraFields: not called CC=1 SCAR=6.9
Pod undocumented
76 0 my $self = shift;
77  
78 0 return $self->{_extraFields};
79 }
80  
81 #----------------------------------------------------------------------------------------
82 0 ▶sub q {
Subroutine q: not called CC=1 SCAR=6.9
Pod undocumented
83 0 my $self = shift;
84  
85 0 return $self->{_q};
86 }
87  
88 #----------------------------------------------------------------------------------------
89 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod undocumented
90 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 ▶ $self->{_userField} = $q->plugin->authn->{userField} || 'username';
Condition0%0/2
$q->plugin->authn->{'userField'} || 'username'
l!l
00
MC/DC0%0/1
$q->plugin->authn->{'userField'} || 'username'
$q->plugin->authn->{'userField'}
Truth table0%0/2
A
A= $q->plugin->authn->{'userField'}
Aresult
11
00
104 0 ▶ $self->{_passwdField} = $q->plugin->authn->{passwdField} || $q->plugin->authn->{passwordField} || 'password';
Condition0%0/5
$q->plugin->authn->{'passwdField'} || $q->plugin->authn->{'passwordField'} || 'password'
l!l
00
$q->plugin->authn->{"passwdField"} or $q->plugin->authn->{"passwordField"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$q->plugin->authn->{'passwdField'} || $q->plugin->authn->{'passwordField'} || 'password'
$q->plugin->authn->{"passwdField"} $q->plugin->authn->{"passwordField"}
Truth table0%0/3
A or B
A= $q->plugin->authn->{"passwdField"}B= $q->plugin->authn->{"passwordField"}
ABresult
1X1
011
000
105 0 ▶ $self->{_activeField} = $q->plugin->authn->{activeField} || 'active';
Condition0%0/2
$q->plugin->authn->{'activeField'} || 'active'
l!l
00
MC/DC0%0/1
$q->plugin->authn->{'activeField'} || 'active'
$q->plugin->authn->{'activeField'}
Truth table0%0/2
A
A= $q->plugin->authn->{'activeField'}
Aresult
11
00
106  
107 0 bless $self, $class;
108  
109 0 ▶ die "Cannot use Authn without Session. Please enable Session plugin" unless $self->q->session;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->q->session 0 0 0
110  
111 0 return $self;
112 }
113  
114 #----------------------------------------------------------------------------------------
115 0 ▶sub passwdField {
Subroutine passwdField: not called CC=1 SCAR=6.9
Pod undocumented
116 0 my $self = shift;
117  
118 0 return $self->{_passwdField};
119 }
120  
121 #----------------------------------------------------------------------------------------
122 0 ▶sub passwdhash {
Subroutine passwdhash: not called CC=1 SCAR=6.9
Pod documented
123 0 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 0 ▶sub primarykey {
Subroutine primarykey: not called CC=1 SCAR=6.9
Pod undocumented
133 0 my $self = shift;
134  
135 0 return $self->{_primarykey};
136 }
137  
138 #----------------------------------------------------------------------------------------
139 0 ▶sub redirectLogin {
Subroutine redirectLogin: not called CC=1 SCAR=6.9
Pod undocumented
140 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 0 ▶sub salt {
Subroutine salt: not called CC=1 SCAR=6.9
Pod undocumented
151 0 my $self = shift;
152  
153 0 return $self->{_salt};
154 }
155  
156 #----------------------------------------------------------------------------------------
157 0 ▶sub table {
Subroutine table: not called CC=1 SCAR=6.9
Pod undocumented
158 0 my $self = shift;
159  
160 0 return $self->{_table};
161 }
162  
163 #----------------------------------------------------------------------------------------
164 0 ▶sub template {
Subroutine template: not called CC=1 SCAR=6.9
Pod undocumented
165 0 my $self = shift;
166  
167 0 return $self->{_template};
168 }
169  
170 #----------------------------------------------------------------------------------------
171 0 ▶sub userField {
Subroutine userField: not called CC=1 SCAR=6.9
Pod undocumented
172 0 my $self = shift;
173  
174 0 return $self->{_userField};
175 }
176  
177 1 1
178  
179 __END__
« Lazy/Utility/Debug.pm ↑ Summary Lazy/Javascript.pm »