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

(-)a/C4/Auth.pm (-2 / +5 lines)
Lines 1830-1837 sub checkpw { Link Here
1830
    # 0 if auth is nok
1830
    # 0 if auth is nok
1831
    # -1 if user bind failed (LDAP only)
1831
    # -1 if user bind failed (LDAP only)
1832
1832
1833
    if ( $patron and ( $patron->account_locked || $patron->password_expired )  ) {
1833
    if ( $patron and ( $patron->account_locked )  ) {
1834
        # Nothing to check, account is locked or password expired
1834
        # Nothing to check, account is locked
1835
    } elsif ($ldap && defined($password)) {
1835
    } elsif ($ldap && defined($password)) {
1836
        my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_);    # EXTERNAL AUTH
1836
        my ( $retval, $retcard, $retuserid ) = checkpw_ldap(@_);    # EXTERNAL AUTH
1837
        if ( $retval == 1 ) {
1837
        if ( $retval == 1 ) {
Lines 1884-1889 sub checkpw { Link Here
1884
    if( $patron ) {
1884
    if( $patron ) {
1885
        if ( $passwd_ok ) {
1885
        if ( $passwd_ok ) {
1886
            $patron->update({ login_attempts => 0 });
1886
            $patron->update({ login_attempts => 0 });
1887
            if( $patron->password_expired ){
1888
                @return = (-2);
1889
            }
1887
        } elsif( !$patron->account_locked ) {
1890
        } elsif( !$patron->account_locked ) {
1888
            $patron->update({ login_attempts => $patron->login_attempts + 1 });
1891
            $patron->update({ login_attempts => $patron->login_attempts + 1 });
1889
        }
1892
        }
(-)a/C4/ILSDI/Services.pm (-1 / +4 lines)
Lines 398-410 sub AuthenticatePatron { Link Here
398
    my $username = $cgi->param('username');
398
    my $username = $cgi->param('username');
399
    my $password = $cgi->param('password');
399
    my $password = $cgi->param('password');
400
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
400
    my ($status, $cardnumber, $userid) = C4::Auth::checkpw( C4::Context->dbh, $username, $password );
401
    if ( $status ) {
401
    if ( $status == 1 ) {
402
        # Track the login
402
        # Track the login
403
        C4::Auth::track_login_daily( $userid );
403
        C4::Auth::track_login_daily( $userid );
404
        # Get the borrower
404
        # Get the borrower
405
        my $patron = Koha::Patrons->find( { userid => $userid } );
405
        my $patron = Koha::Patrons->find( { userid => $userid } );
406
        return { id => $patron->borrowernumber };
406
        return { id => $patron->borrowernumber };
407
    }
407
    }
408
    elsif ( $status == -2 ){
409
        return { code => 'PasswordExpired' };
410
    }
408
    else {
411
    else {
409
        return { code => 'PatronNotFound' };
412
        return { code => 'PatronNotFound' };
410
    }
413
    }
(-)a/t/db_dependent/Auth.t (-1 / +17 lines)
Lines 10-16 use CGI qw ( -utf8 ); Link Here
10
use Test::MockObject;
10
use Test::MockObject;
11
use Test::MockModule;
11
use Test::MockModule;
12
use List::MoreUtils qw/all any none/;
12
use List::MoreUtils qw/all any none/;
13
use Test::More tests => 15;
13
use Test::More tests => 16;
14
use Test::Warn;
14
use Test::Warn;
15
use t::lib::Mocks;
15
use t::lib::Mocks;
16
use t::lib::TestBuilder;
16
use t::lib::TestBuilder;
Lines 425-430 subtest 'Check value of login_attempts in checkpw' => sub { Link Here
425
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
425
    is( $patron->account_locked, 1, 'Check administrative lockout without pref' );
426
};
426
};
427
427
428
subtest 'Check value of login_attempts in checkpw' => sub {
429
    plan tests => 2;
430
431
    t::lib::Mocks::mock_preference('FailedLoginAttempts', 3);
432
    my $patron = $builder->build_object({ class => 'Koha::Patrons' });
433
    $patron->set_password({ password => '123', skip_validation => 1 });
434
435
    my @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
436
    is( $test[0], 1, 'Patron authenticated correctly' );
437
438
    $patron->password_expiration_date('2020-01-01')->store;
439
    @test = checkpw( $dbh, $patron->userid, '123', undef, 'opac', 1 );
440
    is( $test[0], -2, 'Patron returned as expired correctly' );
441
442
};
443
428
subtest '_timeout_syspref' => sub {
444
subtest '_timeout_syspref' => sub {
429
    plan tests => 5;
445
    plan tests => 5;
430
446
(-)a/t/db_dependent/ILSDI_Services.t (-2 / +8 lines)
Lines 42-48 my $builder = t::lib::TestBuilder->new; Link Here
42
42
43
subtest 'AuthenticatePatron test' => sub {
43
subtest 'AuthenticatePatron test' => sub {
44
44
45
    plan tests => 16;
45
    plan tests => 18;
46
46
47
    $schema->storage->txn_begin;
47
    $schema->storage->txn_begin;
48
48
Lines 111-116 subtest 'AuthenticatePatron test' => sub { Link Here
111
    is( $reply->{code}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound" );
111
    is( $reply->{code}, 'PatronNotFound', "non-existing cardnumer/userid - PatronNotFound" );
112
    is( $reply->{id}, undef, "id undef");
112
    is( $reply->{id}, undef, "id undef");
113
113
114
    $query->param( 'username', $borrower->{userid} );
115
    $query->param( 'password', $plain_password );
116
    $seen_patron->password_expiration_date('2020-01-01')->store;
117
    $reply = C4::ILSDI::Services::AuthenticatePatron($query);
118
    is( $reply->{code}, 'PasswordExpired', "correct credentials, expired password not authenticated" );
119
    is( $reply->{id}, undef, "id undef");
120
114
    $schema->storage->txn_rollback;
121
    $schema->storage->txn_rollback;
115
};
122
};
116
123
117
- 

Return to bug 29924