Projekt

Allgemein

Profil

Herunterladen (1,6 KB) Statistiken
| Zweig: | Markierung: | Revision:
8c7e4493 Moritz Bunkus
package SL::Auth::DB;

use DBI;

684e84d8 Sven Schöling
#use SL::Auth;
8c7e4493 Moritz Bunkus
use SL::DBUtils;

c510d88b Sven Schöling
use strict;

8c7e4493 Moritz Bunkus
sub new {
$main::lxdebug->enter_sub();

my $type = shift;
my $self = {};

$self->{auth} = shift;

bless $self, $type;

$main::lxdebug->leave_sub();

return $self;
}

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();
c510d88b Sven Schöling
return SL::Auth->ERR_BACKEND();
8c7e4493 Moritz Bunkus
}

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);

$main::lxdebug->leave_sub();

c510d88b Sven Schöling
return $password eq $stored_password ? SL::Auth->OK() : SL::Auth->ERR_PASSWORD();
8c7e4493 Moritz Bunkus
}

sub can_change_password {
return 1;
}

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();
c510d88b Sven Schöling
return SL::Auth->ERR_BACKEND()
8c7e4493 Moritz Bunkus
}

$password = crypt $password, substr($login, 0, 2) if (!$is_crypted);

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;