kivitendo/SL/Auth/DB.pm @ 79b7fc43
8c7e4493 | Moritz Bunkus | package SL::Auth::DB;
|
||
327e6e57 | Moritz Bunkus | use strict;
|
||
use Carp;
|
||||
43b16238 | Moritz Bunkus | use Scalar::Util qw(weaken);
|
||
327e6e57 | Moritz Bunkus | |||
5d23fb60 | Sven Schöling | use SL::Auth::Constants qw(:all);
|
||
58fdd50d | Moritz Bunkus | use SL::Auth::Password;
|
||
8c7e4493 | Moritz Bunkus | use SL::DBUtils;
|
||
sub new {
|
||||
$main::lxdebug->enter_sub();
|
||||
my $type = shift;
|
||||
my $self = {};
|
||||
$self->{auth} = shift;
|
||||
43b16238 | Moritz Bunkus | weaken $self->{auth};
|
||
8c7e4493 | Moritz Bunkus | |||
bless $self, $type;
|
||||
$main::lxdebug->leave_sub();
|
||||
return $self;
|
||||
}
|
||||
72887d24 | Sven Schöling | sub reset {
|
||
# nothing to do here
|
||||
}
|
||||
8c7e4493 | Moritz Bunkus | sub authenticate {
|
||
$main::lxdebug->enter_sub();
|
||||
my $self = shift;
|
||||
my $login = shift;
|
||||
my $password = shift;
|
||||
d3d6cb31 | Moritz Bunkus | my $stored_password = $self->{auth}->get_stored_password($login);
|
||
8c7e4493 | Moritz Bunkus | |||
327e6e57 | Moritz Bunkus | my ($algorithm, $algorithm2);
|
||
# Empty password hashes in the database mean just that -- empty
|
||||
# passwords. Hash it for easier comparison.
|
||||
58fdd50d | Moritz Bunkus | $stored_password = SL::Auth::Password->hash(password => $stored_password) unless $stored_password;
|
||
($algorithm, $stored_password) = SL::Auth::Password->parse($stored_password);
|
||||
eb8ba476 | Sven Schöling | ($algorithm2, $password) = SL::Auth::Password->parse(SL::Auth::Password->hash(password => $password, algorithm => $algorithm, login => $login));
|
||
8c7e4493 | Moritz Bunkus | |||
$main::lxdebug->leave_sub();
|
||||
5d23fb60 | Sven Schöling | return $password eq $stored_password ? OK : ERR_PASSWORD;
|
||
8c7e4493 | Moritz Bunkus | }
|
||
sub can_change_password {
|
||||
return 1;
|
||||
}
|
||||
d0c2cfbe | Moritz Bunkus | sub requires_cleartext_password {
|
||
return 0;
|
||||
}
|
||||
8c7e4493 | Moritz Bunkus | sub change_password {
|
||
$main::lxdebug->enter_sub();
|
||||
my $self = shift;
|
||||
my $login = shift;
|
||||
my $password = shift;
|
||||
my $is_crypted = shift;
|
||||
my $dbh = $self->{auth}->dbconnect();
|
||||
if (!$dbh) {
|
||||
$main::lxdebug->leave_sub();
|
||||
5d23fb60 | Sven Schöling | return ERR_BACKEND;
|
||
8c7e4493 | Moritz Bunkus | }
|
||
7d42e176 | Moritz Bunkus | $password = SL::Auth::Password->hash(login => $login, password => $password) unless $is_crypted;
|
||
8c7e4493 | Moritz Bunkus | |||
do_query($main::form, $dbh, qq|UPDATE auth."user" SET password = ? WHERE login = ?|, $password, $login);
|
||||
$dbh->commit();
|
||||
$main::lxdebug->leave_sub();
|
||||
return 1;
|
||||
}
|
||||
sub verify_config {
|
||||
return 1;
|
||||
}
|
||||
1;
|