2016-07-12 07:15:26 +02:00
|
|
|
package Lemonldap::NG::Portal::Password::DBI;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Mouse;
|
2020-11-04 16:48:43 +01:00
|
|
|
use Lemonldap::NG::Portal::Main::Constants qw(
|
|
|
|
PE_ERROR
|
|
|
|
PE_PASSWORD_OK
|
|
|
|
);
|
2016-07-12 07:15:26 +02:00
|
|
|
|
2020-11-04 16:48:43 +01:00
|
|
|
extends qw(
|
|
|
|
Lemonldap::NG::Portal::Lib::DBI
|
|
|
|
Lemonldap::NG::Portal::Password::Base
|
2016-07-12 07:15:26 +02:00
|
|
|
|
2020-11-04 16:48:43 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
our $VERSION = '2.0.10';
|
2016-07-12 07:15:26 +02:00
|
|
|
|
2016-07-20 22:47:43 +02:00
|
|
|
sub init {
|
|
|
|
$_[0]->Lemonldap::NG::Portal::Password::Base::init
|
|
|
|
and $_[0]->Lemonldap::NG::Portal::Lib::DBI::init;
|
|
|
|
}
|
|
|
|
|
2016-07-12 07:15:26 +02:00
|
|
|
sub confirm {
|
|
|
|
my ( $self, $req, $pwd ) = @_;
|
|
|
|
return $self->check_password( $req->user, $pwd );
|
|
|
|
}
|
|
|
|
|
|
|
|
sub modifyPassword {
|
2018-11-13 11:30:45 +01:00
|
|
|
my ( $self, $req, $pwd, $useMail ) = @_;
|
2017-06-23 11:23:29 +02:00
|
|
|
|
2018-11-13 11:30:45 +01:00
|
|
|
my $userCol = $useMail ? $self->mailField : $self->pivot;
|
2017-06-23 11:23:29 +02:00
|
|
|
my $passwordCol = $self->conf->{dbiAuthPasswordCol};
|
2017-06-23 11:57:07 +02:00
|
|
|
my $table = $self->conf->{dbiAuthTable};
|
2017-06-23 11:23:29 +02:00
|
|
|
my $dynamicHash = $self->conf->{dbiDynamicHashEnabled} || 0;
|
|
|
|
|
|
|
|
my $passwordsql;
|
|
|
|
if ( $dynamicHash == 1 ) {
|
2017-06-23 11:57:07 +02:00
|
|
|
|
2017-06-23 11:23:29 +02:00
|
|
|
# Dynamic password hashes
|
|
|
|
$passwordsql =
|
2017-06-23 11:57:07 +02:00
|
|
|
$self->dynamic_hash_new_password( $self->dbh, $req->user, $pwd,
|
|
|
|
$table, $userCol, $passwordCol );
|
2017-06-23 11:23:29 +02:00
|
|
|
}
|
2017-06-23 11:57:07 +02:00
|
|
|
else {
|
2017-06-23 11:23:29 +02:00
|
|
|
# Static Password hash
|
2017-06-23 11:57:07 +02:00
|
|
|
$passwordsql =
|
|
|
|
$self->hash_password( "?", $self->conf->{dbiAuthPasswordHash} );
|
2017-06-23 11:23:29 +02:00
|
|
|
}
|
|
|
|
|
2016-07-18 21:38:14 +02:00
|
|
|
eval {
|
2017-06-23 11:23:29 +02:00
|
|
|
my $sth = $self->dbh->prepare(
|
2017-06-23 11:57:07 +02:00
|
|
|
"UPDATE $table SET $passwordCol=$passwordsql WHERE $userCol=?");
|
2018-06-26 19:13:06 +02:00
|
|
|
if ( $passwordsql =~ /.*\?.*/ ) {
|
|
|
|
$sth->execute( $pwd, $req->user );
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$sth->execute( $req->user );
|
|
|
|
}
|
2016-07-18 21:38:14 +02:00
|
|
|
};
|
|
|
|
if ($@) {
|
2016-07-20 09:28:20 +02:00
|
|
|
|
|
|
|
# If connection isn't available, error is displayed by dbh()
|
2017-02-15 07:41:50 +01:00
|
|
|
$self->logger->error("DBI password modification error: $@")
|
2016-07-20 09:28:20 +02:00
|
|
|
if ( $self->_dbh );
|
2016-07-18 21:38:14 +02:00
|
|
|
return PE_ERROR;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return PE_PASSWORD_OK;
|
|
|
|
}
|
2016-07-12 07:15:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
1;
|