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

(-)a/Koha/Patron.pm (-4 / +10 lines)
Lines 1122-1139 sub get_enrollable_clubs { Link Here
1122
1122
1123
my $is_locked = $patron->account_locked
1123
my $is_locked = $patron->account_locked
1124
1124
1125
Return true if the patron has reach the maximum number of login attempts (see pref FailedLoginAttempts).
1125
Return true if the patron has reached the maximum number of login attempts
1126
(see pref FailedLoginAttempts). If login_attempts is < 0, this is interpreted
1127
as an administrative lockout (independent of FailedLoginAttempts; see also
1128
Koha::Patron->lock).
1126
Otherwise return false.
1129
Otherwise return false.
1127
If the pref is not set (empty string, null or 0), the feature is considered as disabled.
1130
If the pref is not set (empty string, null or 0), the feature is considered as
1131
disabled.
1128
1132
1129
=cut
1133
=cut
1130
1134
1131
sub account_locked {
1135
sub account_locked {
1132
    my ($self) = @_;
1136
    my ($self) = @_;
1133
    my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts');
1137
    my $FailedLoginAttempts = C4::Context->preference('FailedLoginAttempts');
1134
    return ( $FailedLoginAttempts
1138
    return 1 if $FailedLoginAttempts
1135
          and $self->login_attempts
1139
          and $self->login_attempts
1136
          and $self->login_attempts >= $FailedLoginAttempts )? 1 : 0;
1140
          and $self->login_attempts >= $FailedLoginAttempts;
1141
    return 1 if ($self->login_attempts || 0) < 0; # administrative lockout
1142
    return 0;
1137
}
1143
}
1138
1144
1139
=head3 can_see_patron_infos
1145
=head3 can_see_patron_infos
(-)a/t/db_dependent/Auth.t (-2 / +17 lines)
Lines 316-322 ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first ha Link Here
316
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
316
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
317
317
318
subtest 'Check value of login_attempts in checkpw' => sub {
318
subtest 'Check value of login_attempts in checkpw' => sub {
319
    plan tests => 6;
319
    plan tests => 11;
320
320
321
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
321
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
322
322
Lines 341-346 subtest 'Check value of login_attempts in checkpw' => sub { Link Here
341
    is( @test, 0, 'checkpw failed again and returns nothing now' );
341
    is( @test, 0, 'checkpw failed again and returns nothing now' );
342
    $patron->discard_changes; # refresh
342
    $patron->discard_changes; # refresh
343
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
343
    is( $patron->login_attempts, 3, 'Login attempts not increased anymore' );
344
345
    # Administrative lockout cannot be undone?
346
    # Pass the right password now (or: add a nice mock).
347
    my $auth = Test::MockModule->new( 'C4::Auth' );
348
    $auth->mock( 'checkpw_hash', sub { return 1; } ); # not for production :)
349
    $patron->login_attempts(0)->store;
350
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
351
    is( $test[0], 1, 'Build confidence in the mock' );
352
    $patron->login_attempts(-1)->store;
353
    is( $patron->account_locked, 1, 'Check administrative lockout' );
354
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
355
    is( @test, 0, 'checkpw gave red' );
356
    $patron->discard_changes; # refresh
357
    is( $patron->login_attempts, -1, 'Still locked out' );
358
    t::lib::Mocks::mock_preference('FailedLoginAttempts', ''); # disable
359
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
344
};
360
};
345
361
346
$schema->storage->txn_rollback;
362
$schema->storage->txn_rollback;
347
- 

Return to bug 21336