From fcc1c09b513afb7320a9986696cb7817bfcabd26 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Thu, 10 Apr 2025 12:31:47 +0100 Subject: [PATCH] Bug 40824: Show error for password history clash in memberentrygen.tt --- .../prog/en/modules/members/memberentrygen.tt | 6 ++++++ members/memberentry.pl | 20 +++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt index a4cee866f38..ee1d7cc2421 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -203,6 +203,9 @@ [% IF ( ERROR_invalid_relationship ) %]
  • Guarantor relationship cannot be left blank according to configuration.
  • [% END %] + [% IF ( ERROR_password_used_before ) %] +
  • This password has been used before. You cannot reuse any of your last [% password_history_count | html %] passwords.
  • + [% END %] [% END %] @@ -1234,6 +1237,9 @@ [% IF ( ERROR_password_has_whitespaces ) %] Password has leading or trailing whitespaces [% END %] + [% IF ( ERROR_password_used_before ) %] + Password has been used before + [% END %]
    Minimum password length: [% patron.category.effective_min_password_length | html %]
    diff --git a/members/memberentry.pl b/members/memberentry.pl index 5f15a105556..a567066e78e 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -48,6 +48,7 @@ use Koha::Patron::HouseboundRoles; use Koha::Policy::Patrons::Cardnumber; use Koha::Plugins; use Koha::SMS::Providers; +use Koha::PatronPasswordHistories; my $input = CGI->new; my %data; @@ -391,6 +392,21 @@ if ( $op eq 'cud-save' || $op eq 'cud-insert' ) { push @errors, 'ERROR_password_too_weak' if $error eq 'too_weak'; push @errors, 'ERROR_password_has_whitespaces' if $error eq 'has_whitespaces'; } + + # Check password history + if ($patron && $is_valid) { # Only check if other validations passed and we have a patron + my $is_used = Koha::PatronPasswordHistories->has_used_password({ + borrowernumber => $patron->borrowernumber, + password => $password, + current_password => $patron->password + }); + + if ($is_used) { + push @errors, 'ERROR_password_used_before'; + my $count = C4::Context->preference('PasswordHistoryCount') || 0; + $template->param( password_history_count => $count ); + } + } } # Validate emails @@ -611,9 +627,9 @@ if ( ( !$nok ) and $nodouble and ( $op eq 'cud-insert' or $op eq 'cud-save' ) ) } } - # should never raise an exception as password validity is checked above + # password validity has been checked above my $password = $newdata{password}; - if ( $password and $password ne '****' ) { + if ( $password and $password ne '****' and $success ) { $patron->set_password( { password => $password } ); } -- 2.39.5