View | Details | Raw Unified | Return to bug 40824
Collapse All | Expand All

(-)a/Koha/Patron.pm (-1 / +27 lines)
Lines 71-76 use Koha::Result::Boolean; Link Here
71
use Koha::Subscription::Routinglists;
71
use Koha::Subscription::Routinglists;
72
use Koha::Token;
72
use Koha::Token;
73
use Koha::Virtualshelves;
73
use Koha::Virtualshelves;
74
use Koha::PatronPasswordHistory;
75
use Koha::PatronPasswordHistories;
74
76
75
use base qw(Koha::Object);
77
use base qw(Koha::Object);
76
78
Lines 1064-1069 sub set_password { Link Here
1064
    my $action   = $args->{action} || "CHANGE PASS";
1066
    my $action   = $args->{action} || "CHANGE PASS";
1065
1067
1066
    unless ( $args->{skip_validation} ) {
1068
    unless ( $args->{skip_validation} ) {
1069
        # Check password history first
1070
        if (Koha::PatronPasswordHistories->has_used_password({
1071
            borrowernumber => $self->borrowernumber,
1072
            password => $password,
1073
            current_password => $self->password
1074
        })) {
1075
            Koha::Exceptions::Password::UsedBefore->throw(
1076
                error => 'Password has been used before'
1077
            );
1078
        }
1079
1067
        my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $self->category );
1080
        my ( $is_valid, $error ) = Koha::AuthUtils::is_password_valid( $password, $self->category );
1068
1081
1069
        if ( !$is_valid ) {
1082
        if ( !$is_valid ) {
Lines 1145-1150 sub set_password { Link Here
1145
        }
1158
        }
1146
    }
1159
    }
1147
1160
1161
    # Store old password in history if there is one and it's different from the new one
1162
    if ($self->password && $self->in_storage) {
1163
        # Get the old password before it's replaced
1164
        my $old_password = $self->get_from_storage->password;
1165
        my $history_count = C4::Context->preference('PasswordHistoryCount') || 0;
1166
1167
        # Always store the old password, regardless of current preference
1168
        # This ensures we maintain history if the preference is increased later
1169
        my $history_record = Koha::PatronPasswordHistory->new({
1170
            borrowernumber => $self->borrowernumber,
1171
            password => $old_password,
1172
        })->store();
1173
    }
1174
1148
    my $digest = Koha::AuthUtils::hash_password($password);
1175
    my $digest = Koha::AuthUtils::hash_password($password);
1149
1176
1150
    $self->password_expiration_date( $self->category->get_password_expiry_date || undef );
1177
    $self->password_expiration_date( $self->category->get_password_expiry_date || undef );
1151
- 

Return to bug 40824