-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.pl
More file actions
32 lines (31 loc) · 918 Bytes
/
Copy pathauthentication.pl
File metadata and controls
32 lines (31 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/perl
plugin 'authentication' => {
session_key => 'mojotask',
stash_key => 'auth',
load_user => sub {
my $self = shift;
my $uid = shift;
my $sth = $self->dbh->prepare('SELECT * FROM user WHERE id = ?');
$sth->execute($uid);
if (my $res = $sth->fetchrow_hashref) {
return $res;
} else {
return undef;
}
},
validate_user => sub {
my $self = shift;
my $user = shift;
my $pass = shift;
my $sth = $self->dbh->prepare('SELECT * FROM user WHERE username = ?');
$sth->execute($user);
if (my $res = $sth->fetchrow_hashref) {
my $salt = substr($res->{'password'}, 0, 2);
return (crypt($pass, $salt) eq $res->{'password'})
? $res->{'id'}
: undef;
} else {
return undef;
}
},
};