From 3f734900f0a86e5478afc22cb77b493500e998e9 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 26 Dec 2018 12:25:54 -0300 Subject: [PATCH] Bug 21547: (follow-up) Rely on Koha::Patron->set_password checks This patch makes the controller just call $patron->set_password and use the exceptions it might raise instead of manually checking the passwor strength. No behaviour change should be expected. It also removes some leftovers. Signed-off-by: Tomas Cohen Arazi Signed-off-by: Nick Clemens --- opac/opac-passwd.pl | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/opac/opac-passwd.pl b/opac/opac-passwd.pl index f183506f27..60d79f61c3 100755 --- a/opac/opac-passwd.pl +++ b/opac/opac-passwd.pl @@ -24,15 +24,14 @@ use CGI qw ( -utf8 ); use C4::Auth; # checkauth, getborrowernumber. use C4::Context; -use Digest::MD5 qw(md5_base64); use C4::Circulation; use C4::Members; use C4::Output; -use Koha::AuthUtils qw(hash_password); use Koha::Patrons; +use Try::Tiny; + my $query = new CGI; -my $dbh = C4::Context->dbh; my ( $template, $borrowernumber, $cookie ) = get_template_and_user( { @@ -60,17 +59,19 @@ if ( C4::Context->preference("OpacPasswordChange") ) { $template->param( 'Error_messages' => '1' ); $template->param( 'passwords_mismatch' => '1' ); } else { - my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $new_password ); - unless ( $is_valid ) { - $error = 'password_too_short' if $error eq 'too_short'; - $error = 'password_too_weak' if $error eq 'too_weak'; - $error = 'password_has_whitespaces' if $error eq 'has_whitespaces'; - } else { - # Password is valid and match + try { $patron->set_password( $new_password ); $template->param( 'password_updated' => '1' ); $template->param( 'borrowernumber' => $borrowernumber ); } + catch { + $error = 'password_too_short' + if $_->isa('Koha::Exceptions::Password::TooShort'); + $error = 'password_too_weak' + if $_->isa('Koha::Exceptions::Password::TooWeak'); + $error = 'password_has_whitespaces' + if $_->isa('Koha::Exceptions::Password::WhitespaceCharacters'); + }; } } else { -- 2.39.5