From 52fb21b3e127e206d3265ae3fdc6cfdcfbcd88db 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 | 23 ++++++++++++----------- opac/opac-passwd.pl | 5 +++-- opac/opac-password-recovery.pl | 3 ++- opac/opac-reset-password.pl | 5 +++-- 5 files changed, 21 insertions(+), 18 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 a567066e78e..6e74242701b 100755 --- a/members/memberentry.pl +++ b/members/memberentry.pl @@ -392,19 +392,20 @@ 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 ( $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 ); } } } @@ -627,7 +628,7 @@ if ( ( !$nok ) and $nodouble and ( $op eq 'cud-insert' or $op eq 'cud-save' ) ) } } - # password validity has been checked above + # password validity has been checked above my $password = $newdata{password}; if ( $password and $password ne '****' and $success ) { $patron->set_password( { password => $password } ); diff --git a/opac/opac-passwd.pl b/opac/opac-passwd.pl index 0b45a39d7b1..8b3f4a46eb5 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 2ca8c6f8956..8b0ae4e73c8 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