lemonldap-ng/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Password/DBI.pm

67 lines
1.7 KiB
Perl
Raw Normal View History

2016-07-12 07:15:26 +02:00
package Lemonldap::NG::Portal::Password::DBI;
use strict;
use Mouse;
2016-07-18 21:38:14 +02:00
use Lemonldap::NG::Portal::Main::Constants qw(PE_PASSWORD_OK PE_ERROR);
2016-07-12 07:15:26 +02:00
extends 'Lemonldap::NG::Portal::Password::Base',
'Lemonldap::NG::Portal::Lib::DBI';
our $VERSION = '2.0.0';
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 {
my ( $self, $req, $pwd, $useMail ) = @_;
my $userCol = $useMail ? $self->mailField : $self->pivot;
my $passwordCol = $self->conf->{dbiAuthPasswordCol};
2017-06-23 11:57:07 +02:00
my $table = $self->conf->{dbiAuthTable};
my $dynamicHash = $self->conf->{dbiDynamicHashEnabled} || 0;
my $passwordsql;
if ( $dynamicHash == 1 ) {
2017-06-23 11:57:07 +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:57:07 +02:00
else {
# Static Password hash
2017-06-23 11:57:07 +02:00
$passwordsql =
$self->hash_password( "?", $self->conf->{dbiAuthPasswordHash} );
}
2016-07-18 21:38:14 +02:00
eval {
my $sth = $self->dbh->prepare(
2017-06-23 11:57:07 +02:00
"UPDATE $table SET $passwordCol=$passwordsql WHERE $userCol=?");
if ( $passwordsql =~ /.*\?.*/ ) {
$sth->execute( $pwd, $req->user );
}
else {
$sth->execute( $req->user );
}
2016-07-18 21:38:14 +02:00
};
if ($@) {
# 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: $@")
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;