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

(-)a/C4/Auth.pm (-37 / +23 lines)
Lines 2040-2056 sub checkpw { Link Here
2040
    }
2040
    }
2041
2041
2042
    if ($check_internal_as_fallback) {
2042
    if ($check_internal_as_fallback) {
2043
2043
        # INTERNAL AUTH
2044
        # INTERNAL AUTH
2044
        @return    = checkpw_internal( $userid, $password, $no_set_userenv );
2045
        @return    = checkpw_internal( $userid, $password, $no_set_userenv );
2045
        $passwd_ok = 1                                                   if $return[0] > 0;    # 1 or 2
2046
        $passwd_ok = 1 if $return[0] > 0;                                       # 1 or 2
2046
        $patron    = Koha::Patrons->find( { cardnumber => $return[1] } ) if $passwd_ok;
2047
        $patron    = $return[3];
2047
        push @return, $patron if $patron;
2048
    }
2048
    }
2049
2049
2050
    if ( defined $userid && !$patron ) {
2050
    if ( defined $userid && !$patron ) {
2051
        $patron = Koha::Patrons->find( { userid     => $userid } );
2051
        $patron = Koha::Patrons->find( { userid     => $userid } );
2052
        $patron = Koha::Patrons->find( { cardnumber => $userid } ) unless $patron;
2052
        $patron = Koha::Patrons->find( { cardnumber => $userid } ) unless $patron;
2053
        push @return, $patron if $check_internal_as_fallback;
2053
        push @return, $patron if $check_internal_as_fallback;    # We pass back the patron if authentication fails
2054
    }
2054
    }
2055
2055
2056
    if ($patron) {
2056
    if ($patron) {
Lines 2080-2120 sub checkpw_internal { Link Here
2080
    my ( $userid, $password, $no_set_userenv ) = @_;
2080
    my ( $userid, $password, $no_set_userenv ) = @_;
2081
2081
2082
    $password = Encode::encode( 'UTF-8', $password )
2082
    $password = Encode::encode( 'UTF-8', $password )
2083
      if Encode::is_utf8($password);
2083
        if Encode::is_utf8($password);
2084
2085
    my $dbh = C4::Context->dbh;
2086
    my $sth =
2087
      $dbh->prepare(
2088
        "select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where userid=?"
2089
      );
2090
    $sth->execute($userid);
2091
    if ( $sth->rows ) {
2092
        my ( $stored_hash, $cardnumber, $borrowernumber, $userid, $firstname,
2093
            $surname, $branchcode, $branchname, $flags )
2094
          = $sth->fetchrow;
2095
2096
        if ( checkpw_hash( $password, $stored_hash ) ) {
2097
2084
2098
            C4::Context->set_userenv( "$borrowernumber", $userid, $cardnumber,
2085
    my $patron = Koha::Patrons->find( { userid => $userid } );
2099
                $firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv;
2086
    if ($patron) {
2100
            return 1, $cardnumber, $userid;
2087
        if ( checkpw_hash( $password, $patron->password ) ) {
2088
            my $borrowernumber = $patron->borrowernumber;
2089
            C4::Context->set_userenv(
2090
                "$borrowernumber", $patron->userid, $patron->cardnumber,
2091
                $patron->firstname, $patron->surname, $patron->branchcode, $patron->library->branchname, $patron->flags
2092
            ) unless $no_set_userenv;
2093
            return 1, $patron->cardnumber, $patron->userid, $patron;
2101
        }
2094
        }
2102
    }
2095
    }
2103
    $sth =
2096
    $patron = Koha::Patrons->find( { cardnumber => $userid } );
2104
      $dbh->prepare(
2097
    if ($patron) {
2105
        "select password,cardnumber,borrowernumber,userid,firstname,surname,borrowers.branchcode,branches.branchname,flags from borrowers join branches on borrowers.branchcode=branches.branchcode where cardnumber=?"
2098
        if ( checkpw_hash( $password, $patron->password ) ) {
2106
      );
2099
            my $borrowernumber = $patron->borrowernumber;
2107
    $sth->execute($userid);
2100
            C4::Context->set_userenv(
2108
    if ( $sth->rows ) {
2101
                "$borrowernumber", $patron->userid, $patron->cardnumber,
2109
        my ( $stored_hash, $cardnumber, $borrowernumber, $userid, $firstname,
2102
                $patron->firstname, $patron->surname, $patron->branchcode, $patron->library->branchname, $patron->flags
2110
            $surname, $branchcode, $branchname, $flags )
2103
            ) unless $no_set_userenv;
2111
          = $sth->fetchrow;
2104
            return 1, $patron->cardnumber, $patron->userid, $patron;
2112
2113
        if ( checkpw_hash( $password, $stored_hash ) ) {
2114
2115
            C4::Context->set_userenv( $borrowernumber, $userid, $cardnumber,
2116
                $firstname, $surname, $branchcode, $branchname, $flags ) unless $no_set_userenv;
2117
            return 1, $cardnumber, $userid;
2118
        }
2105
        }
2119
    }
2106
    }
2120
    return 0;
2107
    return 0;
2121
- 

Return to bug 36575