Skip to content
Snippets Groups Projects
Commit cb7bbd5a authored by Josef Moravec's avatar Josef Moravec Committed by Demian Katz
Browse files

Add changePassword to Koha ILSDI driver (#1229)

parent 09785828
No related merge requests found
...@@ -1926,6 +1926,49 @@ class KohaILSDI extends \VuFind\ILS\Driver\AbstractBase implements ...@@ -1926,6 +1926,49 @@ class KohaILSDI extends \VuFind\ILS\Driver\AbstractBase implements
} }
} }
/**
* Change Password
*
* This method changes patron's password
*
* @param array $detail An associative array with three keys
* patron - The patron array from patronLogin
* oldPassword - Old password
* newPassword - New password
*
* @return array An associative array with keys:
* success - boolean, true if change was made
* status - string, A status message - subject to translation
*/
public function changePassword($detail)
{
if (!$this->db) {
$this->initDb();
}
$sql = "UPDATE borrowers SET password = ? WHERE borrowernumber = ?";
$keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$max = mb_strlen($keyspace, '8bit') - 1;
$salt = '';
for ($i = 0; $i < 16; ++$i) { // 16 is length of salt
$salt .= $keyspace[random_int(0, $max)];
}
$salt = base64_encode($salt);
$newPassword_hashed = crypt($detail['newPassword'], '$2a$08$' . $salt);
try {
$stmt = $this->db->prepare($sql);
$result = $stmt->execute(
[ $newPassword_hashed, $detail['patron']['id'] ]
);
} catch (Exception $e) {
return [ 'success' => false, 'status' => $e->getMessage() ];
}
return [
'success' => $result,
'status' => $result ? 'new_password_success'
: 'password_error_not_unique'
];
}
/** /**
* Convert a database date to a displayable date. * Convert a database date to a displayable date.
* *
......
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