diff --git a/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php b/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php index 268745b5e041d71b6a29a7935dfbd13b23f90ed8..ccdba432e7ab1a0bacd24300fff69e5e0f443c50 100644 --- a/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php +++ b/module/VuFind/src/VuFind/ILS/Driver/KohaILSDI.php @@ -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. *