Skip to content
Snippets Groups Projects
Commit e0ccbd77 authored by Galen Charlton's avatar Galen Charlton
Browse files

Update Koha driver to recognize either MD5 or bcrypt password hashes

Koha 3.14 and later uses bcrypt to hash passwords; previously
it used md5_base64. This patch updates the driver so that it can
handle both.

Thanks to Olugbenga Adara for testing.
parent 0b614f64
Branches
Tags
No related merge requests found
...@@ -481,10 +481,31 @@ class Koha extends AbstractBase ...@@ -481,10 +481,31 @@ class Koha extends AbstractBase
$patron = []; $patron = [];
$row = ''; $row = '';
// Koha uses MD5_BASE64 encoding to save borrowers' passwords, function $stored_hash = '';
// 'rtrim' is used to discard trailing '=' signs, suitable for pushing try {
// into MySQL database $sql = "select password from borrowers where userid = :username";
$db_pwd = rtrim(base64_encode(pack('H*', md5($password))), '='); $sqlStmt = $this->db->prepare($sql);
$sqlStmt->execute([':username' => $username]);
$row = $sqlStmt->fetch();
if ($row) {
$stored_hash = $row['password'];
} else {
return null;
}
}
catch (PDOException $e) {
throw new ILSException($e->getMessage());
}
if ("$2a$" == substr($stored_hash, 0, 4)) {
// Newer Koha version that uses bcrypt
$db_pwd = crypt($password, $stored_hash);
} else {
// Koha used to use MD5_BASE64 encoding to save borrowers' passwords, function
// 'rtrim' is used to discard trailing '=' signs, suitable for pushing
// into MySQL database
$db_pwd = rtrim(base64_encode(pack('H*', md5($password))), '=');
}
$sql = "select borrowernumber as ID, firstname as FNAME, " . $sql = "select borrowernumber as ID, firstname as FNAME, " .
"surname as LNAME, email as EMAIL from borrowers " . "surname as LNAME, email as EMAIL from borrowers " .
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment