« blib/lib/Lemonldap/NG/Portal/2F/Register/Yubikey.pm
↑ Summary
blib/lib/Lemonldap/NG/Portal/Captcha/ReCaptcha.pm »
| 1 | package Lemonldap::NG::Portal::Password::DBI; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use Mouse; | ||
| 5 | use Lemonldap::NG::Portal::Main::Constants qw( | ||
| 6 | PE_ERROR | ||
| 7 | PE_PASSWORD_OK | ||
| 8 | ); | ||
| 9 | |||
| 10 | extends qw( | ||
| 11 | Lemonldap::NG::Portal::Lib::DBI | ||
| 12 | Lemonldap::NG::Portal::Password::Base | ||
| 13 | |||
| 14 | ); | ||
| 15 | |||
| 16 | our $VERSION = '2.0.16'; | ||
| 17 | |||
| 18 | sub init { | ||
| 19 | my ($self) = @_; | ||
| 20 | $self->Lemonldap::NG::Portal::Password::Base::init | ||
| 21 | and $self->Lemonldap::NG::Portal::Lib::DBI::init; | ||
| 22 | } | ||
| 23 | |||
| 24 | sub confirm { | ||
| 25 | my ( $self, $req, $pwd ) = @_; | ||
| 26 | return $self->check_password( $req, $pwd ); | ||
| 27 | } | ||
| 28 | |||
| 29 | sub modifyPassword { | ||
| 30 | my ( $self, $req, $pwd, %args ) = @_; | ||
| 31 | my $userCol = $args{useMail} ? $self->mailField : $self->pivot; | ||
| 32 | my $passwordCol = $self->conf->{dbiAuthPasswordCol}; | ||
| 33 | my $table = $self->conf->{dbiAuthTable}; | ||
| 34 | my $dynamicHash = $self->conf->{dbiDynamicHashEnabled} || 0; | ||
| 35 | my $passwordsql; | ||
| 36 | my $stored_value; | ||
| 37 | |||
| 38 | if ( $dynamicHash == 1 ) { | ||
| 39 | |||
| 40 | $passwordsql = "?"; | ||
| 41 | |||
| 42 | # Dynamic password hashes | ||
| 43 | $stored_value = | ||
| 44 | $self->get_dynamic_hash_new_password( $req, $self->dbh, $req->user, | ||
| 45 | $pwd, $table, $userCol, $passwordCol ); | ||
| 46 | } | ||
| 47 | else { | ||
| 48 | # Static Password hash | ||
| 49 | $passwordsql = | ||
| 50 | $self->hash_password( "?", $self->conf->{dbiAuthPasswordHash} ); | ||
| 51 | $stored_value = $pwd; | ||
| 52 | } | ||
| 53 | |||
| 54 | eval { | ||
| 55 | my $sth = $self->dbh->prepare( | ||
| 56 | "UPDATE $table SET $passwordCol=$passwordsql WHERE $userCol=?"); | ||
| 57 | $sth->execute( $stored_value, $req->user ); | ||
| 58 | }; | ||
| 59 | if ($@) { | ||
| 60 | |||
| 61 | # If connection isn't available, error is displayed by dbh() | ||
| 62 | $self->logger->error("DBI password modification error: $@") | ||
| 63 | if ( $self->_dbh ); | ||
| 64 | return PE_ERROR; | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | return PE_PASSWORD_OK; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; |