From bd647993064abe5c7046941e16b9cd4785245d82 Mon Sep 17 00:00:00 2001 From: Jacob O'Mara Date: Thu, 14 Aug 2025 11:52:19 +0100 Subject: [PATCH] Bug 40824: Show category-specific password history count in error messages Update all password error message handlers to use the category-specific effective_password_history_count method instead of the global system preference: - members/member-password.pl - members/memberentry.pl - opac/opac-passwd.pl - opac/opac-password-recovery.pl - opac/opac-reset-password.pl --- members/member-password.pl | 3 +-- members/memberentry.pl | 17 +++++++++-------- opac/opac-passwd.pl | 5 +++-- opac/opac-password-recovery.pl | 3 ++- opac/opac-reset-password.pl | 5 +++-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/members/member-password.pl b/members/member-password.pl index 67406b2356b..be9d8bd5510 100755 --- a/members/member-password.pl +++ b/members/member-password.pl @@ -82,9 +82,8 @@ if ( $op eq 'cud-update' && defined($newpassword) and not @errors ) { } elsif ( $_->isa('Koha::Exceptions::Password::Plugin') ) { push @errors, 'ERROR_from_plugin'; } elsif ( $_->isa('Koha::Exceptions::Password::UsedBefore') ) { - my $count = C4::Context->preference('PasswordHistoryCount') || 0; push @errors, 'ERROR_password_used_before'; - $template->param( 'password_history_count' => $count ); + $template->param( 'password_history_count' => $patron->category->effective_password_history_count ); } else { push( @errors, 'BADUSERID' ); } diff --git a/members/memberentry.pl b/members/memberentry.pl index 3f7848575a5..98293ca2b76 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -394,17 +394,18 @@ if ( $op eq 'cud-save' || $op eq 'cud-insert' ) { } # 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 ( $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 ); + $template->param( password_history_count => $patron->category->effective_password_history_count ); } } } diff --git a/opac/opac-passwd.pl b/opac/opac-passwd.pl index 85deabda96d..f12758a0747 100755 --- a/opac/opac-passwd.pl +++ b/opac/opac-passwd.pl @@ -68,9 +68,10 @@ if ( $patron->category->effective_change_password ) { if $_->isa('Koha::Exceptions::Password::TooWeak'); $error = 'password_has_whitespaces' if $_->isa('Koha::Exceptions::Password::WhitespaceCharacters'); - if ($_->isa('Koha::Exceptions::Password::UsedBefore')) { + if ( $_->isa('Koha::Exceptions::Password::UsedBefore') ) { $error = 'password_used_before'; - $template->param( 'password_history_count' => C4::Context->preference('PasswordHistoryCount') ); + $template->param( + 'password_history_count' => $patron->category->effective_password_history_count ); } }; } diff --git a/opac/opac-password-recovery.pl b/opac/opac-password-recovery.pl index e45f2d9015b..f27f7c5cfa0 100755 --- a/opac/opac-password-recovery.pl +++ b/opac/opac-password-recovery.pl @@ -179,8 +179,9 @@ if ( $op eq 'cud-sendEmail' || $op eq 'cud-resendEmail' ) { $error = 'password_has_whitespaces'; } elsif ( $_->isa('Koha::Exceptions::Password::TooWeak') ) { $error = 'password_too_weak'; - } elsif ($_->isa('Koha::Exceptions::Password::UsedBefore')) { + } elsif ( $_->isa('Koha::Exceptions::Password::UsedBefore') ) { $error = 'password_used_before'; + $template->param( password_history_count => $borrower->category->effective_password_history_count ); } }; } diff --git a/opac/opac-reset-password.pl b/opac/opac-reset-password.pl index ae0eab438a9..ffd75336bac 100755 --- a/opac/opac-reset-password.pl +++ b/opac/opac-reset-password.pl @@ -71,9 +71,10 @@ if ( $op eq 'cud-update' ) { if $_->isa('Koha::Exceptions::Password::TooWeak'); $error = 'password_has_whitespaces' if $_->isa('Koha::Exceptions::Password::WhitespaceCharacters'); - if ($_->isa('Koha::Exceptions::Password::UsedBefore')) { + if ( $_->isa('Koha::Exceptions::Password::UsedBefore') ) { $template->param( password_used_before => 1 ); - $template->param( password_history_count => C4::Context->preference('PasswordHistoryCount') ); + $template->param( + password_history_count => $patron->category->effective_password_history_count ); } $template->param( 'error' => $error ); }; -- 2.39.5