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

(-)a/C4/Auth.pm (-5 / +5 lines)
Lines 1738-1744 sub get_session { Link Here
1738
}
1738
}
1739
1739
1740
sub checkpw {
1740
sub checkpw {
1741
    my ( $dbh, $userid, $password, $query, $type ) = @_;
1741
    my ( $dbh, $userid, $password, $query, $type, $no_set_userenv ) = @_;
1742
    $type = 'opac' unless $type;
1742
    $type = 'opac' unless $type;
1743
    if ($ldap) {
1743
    if ($ldap) {
1744
        $debug and print STDERR "## checkpw - checking LDAP\n";
1744
        $debug and print STDERR "## checkpw - checking LDAP\n";
Lines 1778-1788 sub checkpw { Link Here
1778
    }
1778
    }
1779
1779
1780
    # INTERNAL AUTH
1780
    # INTERNAL AUTH
1781
    return checkpw_internal(@_)
1781
    return checkpw_internal( $dbh, $userid, $password, $no_set_userenv);
1782
}
1782
}
1783
1783
1784
sub checkpw_internal {
1784
sub checkpw_internal {
1785
    my ( $dbh, $userid, $password ) = @_;
1785
    my ( $dbh, $userid, $password, $no_set_userenv ) = @_;
1786
1786
1787
    $password = Encode::encode( 'UTF-8', $password )
1787
    $password = Encode::encode( 'UTF-8', $password )
1788
      if Encode::is_utf8($password);
1788
      if Encode::is_utf8($password);
Lines 1812-1818 sub checkpw_internal { Link Here
1812
        if ( checkpw_hash( $password, $stored_hash ) ) {
1812
        if ( checkpw_hash( $password, $stored_hash ) ) {
1813
1813
1814
            C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber,
1814
            C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber,
1815
                $firstname, $surname, $branchcode, $branchname, $flags );
1815
                $firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv;
1816
            return 1, $cardnumber, $userid;
1816
            return 1, $cardnumber, $userid;
1817
        }
1817
        }
1818
    }
1818
    }
Lines 1829-1835 sub checkpw_internal { Link Here
1829
        if ( checkpw_hash( $password, $stored_hash ) ) {
1829
        if ( checkpw_hash( $password, $stored_hash ) ) {
1830
1830
1831
            C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber,
1831
            C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber,
1832
                $firstname, $surname, $branchcode, $branchname, $flags );
1832
                $firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv;
1833
            return 1, $cardnumber, $userid;
1833
            return 1, $cardnumber, $userid;
1834
        }
1834
        }
1835
    }
1835
    }
(-)a/C4/SIP/ILS/Patron.pm (-1 / +1 lines)
Lines 201-207 sub check_password { Link Here
201
201
202
    my $dbh = C4::Context->dbh;
202
    my $dbh = C4::Context->dbh;
203
    my $ret = 0;
203
    my $ret = 0;
204
    ($ret) = checkpw( $dbh, $self->{userid}, $pwd );
204
    ($ret) = checkpw( $dbh, $self->{userid}, $pwd, undef, undef, 1 ); # dbh, userid, query, type, no_set_userenv
205
    return $ret;
205
    return $ret;
206
}
206
}
207
207
(-)a/t/db_dependent/Auth.t (-10 / +24 lines)
Lines 8-29 use Modern::Perl; Link Here
8
use CGI qw ( -utf8 );
8
use CGI qw ( -utf8 );
9
use Test::MockModule;
9
use Test::MockModule;
10
use List::MoreUtils qw/all any none/;
10
use List::MoreUtils qw/all any none/;
11
use Test::More tests => 13;
11
use Test::More tests => 18;
12
use Test::Warn;
12
use Test::Warn;
13
use t::lib::Mocks;
13
use t::lib::Mocks;
14
use t::lib::TestBuilder;
15
16
use C4::Auth qw(checkpw);
14
use C4::Members;
17
use C4::Members;
15
use Koha::AuthUtils qw/hash_password/;
18
use Koha::AuthUtils qw/hash_password/;
19
use Koha::Database;
16
20
17
BEGIN {
21
BEGIN {
18
        use_ok('C4::Auth');
22
    use_ok('C4::Auth');
19
}
23
}
20
24
21
my $dbh = C4::Context->dbh;
25
my $schema = Koha::Database->schema;
22
26
$schema->storage->txn_begin;
23
# Start transaction
27
my $builder = t::lib::TestBuilder->new;
24
$dbh->{AutoCommit} = 0;
28
my $dbh     = C4::Context->dbh;
25
$dbh->{RaiseError} = 1;
26
27
29
28
# get_template_and_user tests
30
# get_template_and_user tests
29
31
Lines 176-179 my $hash2 = hash_password('password'); Link Here
176
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
178
ok(C4::Auth::checkpw_hash('password', $hash1), 'password validates with first hash');
177
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
179
ok(C4::Auth::checkpw_hash('password', $hash2), 'password validates with second hash');
178
180
179
$dbh->rollback;
181
my $patron = $builder->build( { source => 'Borrower' } );
182
changepassword( $patron->{userid}, $patron->{borrowernumber}, $hash1 );
183
my $library = $builder->build(
184
    {
185
        source => 'Branch',
186
    }
187
);
188
189
C4::Context->set_userenv(0,0,0,'firstname','surname', $library->{branchcode}, 'Library 1', 0, '', '');
190
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv gives correct branch' );
191
ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 1 ), 'checkpw returns true' );
192
is( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is preserved if no_set_userenv is true' );
193
ok( checkpw( $dbh, $patron->{userid}, 'password', undef, undef, 0 ), 'checkpw still returns true' );
194
isnt( C4::Context->userenv->{branch}, $library->{branchcode}, 'Userenv branch is overwritten if no_set_userenv is false' );
180
- 

Return to bug 16492