Lines 2023-2039
sub checkpw {
Link Here
|
2023 |
} |
2023 |
} |
2024 |
|
2024 |
|
2025 |
if ($check_internal_as_fallback) { |
2025 |
if ($check_internal_as_fallback) { |
|
|
2026 |
|
2026 |
# INTERNAL AUTH |
2027 |
# INTERNAL AUTH |
2027 |
@return = checkpw_internal( $userid, $password, $no_set_userenv ); |
2028 |
@return = checkpw_internal( $userid, $password, $no_set_userenv ); |
2028 |
$passwd_ok = 1 if $return[0] > 0; # 1 or 2 |
2029 |
$passwd_ok = 1 if $return[0] > 0; # 1 or 2 |
2029 |
$patron = Koha::Patrons->find( { cardnumber => $return[1] } ) if $passwd_ok; |
2030 |
$patron = $return[3]; |
2030 |
push @return, $patron if $patron; |
|
|
2031 |
} |
2031 |
} |
2032 |
|
2032 |
|
2033 |
if ( defined $userid && !$patron ) { |
2033 |
if ( defined $userid && !$patron ) { |
2034 |
$patron = Koha::Patrons->find( { userid => $userid } ); |
2034 |
$patron = Koha::Patrons->find( { userid => $userid } ); |
2035 |
$patron = Koha::Patrons->find( { cardnumber => $userid } ) unless $patron; |
2035 |
$patron = Koha::Patrons->find( { cardnumber => $userid } ) unless $patron; |
2036 |
push @return, $patron if $check_internal_as_fallback; |
2036 |
push @return, $patron if $check_internal_as_fallback; # We pass back the patron if authentication fails |
2037 |
} |
2037 |
} |
2038 |
|
2038 |
|
2039 |
if ($patron) { |
2039 |
if ($patron) { |
Lines 2063-2103
sub checkpw_internal {
Link Here
|
2063 |
my ( $userid, $password, $no_set_userenv ) = @_; |
2063 |
my ( $userid, $password, $no_set_userenv ) = @_; |
2064 |
|
2064 |
|
2065 |
$password = Encode::encode( 'UTF-8', $password ) |
2065 |
$password = Encode::encode( 'UTF-8', $password ) |
2066 |
if Encode::is_utf8($password); |
2066 |
if Encode::is_utf8($password); |
2067 |
|
|
|
2068 |
my $dbh = C4::Context->dbh; |
2069 |
my $sth = |
2070 |
$dbh->prepare( |
2071 |
"select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where userid=?" |
2072 |
); |
2073 |
$sth->execute($userid); |
2074 |
if ( $sth->rows ) { |
2075 |
my ( $stored_hash, $cardnumber, $borrowernumber, $userid, $firstname, |
2076 |
$surname, $branchcode, $branchname, $flags ) |
2077 |
= $sth->fetchrow; |
2078 |
|
2079 |
if ( checkpw_hash( $password, $stored_hash ) ) { |
2080 |
|
2067 |
|
2081 |
C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber, |
2068 |
my $patron = Koha::Patrons->find( { userid => $userid } ); |
2082 |
$firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv; |
2069 |
if ($patron) { |
2083 |
return 1, $cardnumber, $userid; |
2070 |
if ( checkpw_hash( $password, $patron->password ) ) { |
|
|
2071 |
my $borrowernumber = $patron->borrowernumber; |
2072 |
C4::Context->set_userenv( |
2073 |
"$borrowernumber", $patron->userid, $patron->cardnumber, |
2074 |
$patron->firstname, $patron->surname, $patron->branchcode, $patron->library->branchname, $patron->flags |
2075 |
) unless $no_set_userenv; |
2076 |
return 1, $patron->cardnumber, $patron->userid, $patron; |
2084 |
} |
2077 |
} |
2085 |
} |
2078 |
} |
2086 |
$sth = |
2079 |
$patron = Koha::Patrons->find( { cardnumber => $userid } ); |
2087 |
$dbh->prepare( |
2080 |
if ($patron) { |
2088 |
"select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where cardnumber=?" |
2081 |
if ( checkpw_hash( $password, $patron->password ) ) { |
2089 |
); |
2082 |
my $borrowernumber = $patron->borrowernumber; |
2090 |
$sth->execute($userid); |
2083 |
C4::Context->set_userenv( |
2091 |
if ( $sth->rows ) { |
2084 |
"$borrowernumber", $patron->userid, $patron->cardnumber, |
2092 |
my ( $stored_hash, $cardnumber, $borrowernumber, $userid, $firstname, |
2085 |
$patron->firstname, $patron->surname, $patron->branchcode, $patron->library->branchname, $patron->flags |
2093 |
$surname, $branchcode, $branchname, $flags ) |
2086 |
) unless $no_set_userenv; |
2094 |
= $sth->fetchrow; |
2087 |
return 1, $patron->cardnumber, $patron->userid, $patron; |
2095 |
|
|
|
2096 |
if ( checkpw_hash( $password, $stored_hash ) ) { |
2097 |
|
2098 |
C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber, |
2099 |
$firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv; |
2100 |
return 1, $cardnumber, $userid; |
2101 |
} |
2088 |
} |
2102 |
} |
2089 |
} |
2103 |
return 0; |
2090 |
return 0; |
2104 |
- |
|
|