Bugzilla – Attachment 189206 Details for
Bug 40824
Add option to prevent re-use of passwords
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40824: Check password history for clashes when saving password
Bug-40824-Check-password-history-for-clashes-when-.patch (text/plain), 2.23 KB, created by
Jacob O'Mara
on 2025-11-06 19:34:14 UTC
(
hide
)
Description:
Bug 40824: Check password history for clashes when saving password
Filename:
MIME Type:
Creator:
Jacob O'Mara
Created:
2025-11-06 19:34:14 UTC
Size:
2.23 KB
patch
obsolete
>From b484a10ec4779d6c3fd7e3b313b294e7e8a27cdb Mon Sep 17 00:00:00 2001 >From: Jacob O'Mara <jacob.omara@openfifth.co.uk> >Date: Thu, 10 Apr 2025 12:30:45 +0100 >Subject: [PATCH] Bug 40824: Check password history for clashes when saving > password > >--- > Koha/Patron.pm | 27 +++++++++++++++++++++++++++ > 1 file changed, 27 insertions(+) > >diff --git a/Koha/Patron.pm b/Koha/Patron.pm >index 162ea03630c..6af253a13b1 100644 >--- a/Koha/Patron.pm >+++ b/Koha/Patron.pm >@@ -71,6 +71,8 @@ use Koha::Result::Boolean; > use Koha::Subscription::Routinglists; > use Koha::Token; > use Koha::Virtualshelves; >+use Koha::PatronPasswordHistory; >+use Koha::PatronPasswordHistories; > > use base qw(Koha::Object); > >@@ -1064,6 +1066,17 @@ sub set_password { > my $action = $args->{action} || "CHANGE PASS"; > > unless ( $args->{skip_validation} ) { >+ # Check password history first >+ if (Koha::PatronPasswordHistories->has_used_password({ >+ borrowernumber => $self->borrowernumber, >+ password => $password, >+ current_password => $self->password >+ })) { >+ Koha::Exceptions::Password::UsedBefore->throw( >+ error => 'Password has been used before' >+ ); >+ } >+ > my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $self->category ); > > if ( !$is_valid ) { >@@ -1145,6 +1158,20 @@ sub set_password { > } > } > >+ # Store old password in history if there is one and it's different from the new one >+ if ($self->password && $self->in_storage) { >+ # Get the old password before it's replaced >+ my $old_password = $self->get_from_storage->password; >+ my $history_count = C4::Context->preference('PasswordHistoryCount') || 0; >+ >+ # Always store the old password, regardless of current preference >+ # This ensures we maintain history if the preference is increased later >+ my $history_record = Koha::PatronPasswordHistory->new({ >+ borrowernumber => $self->borrowernumber, >+ password => $old_password, >+ })->store(); >+ } >+ > my $digest = Koha::AuthUtils::hash_password($password); > > $self->password_expiration_date( $self->category->get_password_expiry_date || undef ); >-- >2.39.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40824
:
186511
|
186512
|
186513
|
186514
|
186515
|
186516
|
186517
|
186518
|
186519
|
186520
|
186521
|
186522
|
186523
|
186524
|
186525
|
186526
|
186527
|
189201
|
189202
|
189203
|
189204
|
189205
| 189206 |
189207
|
189208
|
189209
|
189210
|
189211
|
189212
|
189213
|
189214
|
189215
|
189216
|
189217