X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FAuth%2FDB.pm;h=93e5cc0b36d280fe497e6e1db7f3c72ea1aecec3;hb=47db6ae13df64092d401896ec476b9335e9ec807;hp=cc264cafa97e996660fa721604959dbdefaefef8;hpb=8c7e44938a661e035f62840e1e177353240ace5d;p=kivitendo-erp.git diff --git a/SL/Auth/DB.pm b/SL/Auth/DB.pm index cc264cafa..93e5cc0b3 100644 --- a/SL/Auth/DB.pm +++ b/SL/Auth/DB.pm @@ -1,8 +1,12 @@ package SL::Auth::DB; -use DBI; +use strict; -use SL::Auth; +use Carp; +use Scalar::Util qw(weaken); + +use SL::Auth::Constants qw(:all); +use SL::Auth::Password; use SL::DBUtils; sub new { @@ -12,6 +16,7 @@ sub new { my $self = {}; $self->{auth} = shift; + weaken $self->{auth}; bless $self, $type; @@ -20,36 +25,38 @@ sub new { return $self; } +sub reset { + # nothing to do here +} + sub authenticate { $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(); - return SL::Auth::ERR_BACKEND; - } + my $stored_password = $self->{auth}->get_stored_password($login); - my $query = qq|SELECT password FROM auth."user" WHERE login = ?|; - my ($stored_password) = $dbh->selectrow_array($query, undef, $login); - - $password = crypt $password, substr($login, 0, 2) if (!$password || !$is_crypted); - $stored_password = crypt $stored_password, substr($login, 0, 2) if (!$stored_password); + # Empty password hashes in the database mean just that -- empty + # passwords. Hash it for easier comparison. + $stored_password = SL::Auth::Password->hash(password => $stored_password) unless $stored_password; + my ($algorithm) = SL::Auth::Password->parse($stored_password); + my $hashed_password = SL::Auth::Password->hash(password => $password, algorithm => $algorithm, login => $login, stored_password => $stored_password); $main::lxdebug->leave_sub(); - return $password eq $stored_password ? SL::Auth::OK : SL::Auth::ERR_PASSWORD; + return $hashed_password eq $stored_password ? OK : ERR_PASSWORD; } sub can_change_password { return 1; } +sub requires_cleartext_password { + return 0; +} + sub change_password { $main::lxdebug->enter_sub(); @@ -62,10 +69,10 @@ sub change_password { if (!$dbh) { $main::lxdebug->leave_sub(); - return SL::Auth::ERR_BACKEND + return ERR_BACKEND; } - $password = crypt $password, substr($login, 0, 2) if (!$is_crypted); + $password = SL::Auth::Password->hash(login => $login, password => $password) unless $is_crypted; do_query($main::form, $dbh, qq|UPDATE auth."user" SET password = ? WHERE login = ?|, $password, $login);