Horde_Auth_Sql::resetPassword PHP Method

resetPassword() public method

Reset a user's password. Used for example when the user does not remember the existing password.
public resetPassword ( string $userId ) : string
$userId string The user id for which to reset the password.
return string The new password on success.
    public function resetPassword($userId)
    {
        /* Get a new random password. */
        $password = Horde_Auth::genRandomPassword();
        /* Build the SQL query. */
        $query = sprintf('UPDATE %s SET %s = ?', $this->_params['table'], $this->_params['password_field']);
        $values = array(Horde_Auth::getCryptedPassword($password, '', $this->_params['encryption'], $this->_params['show_encryption']));
        if (!empty($this->_params['soft_expiration_field'])) {
            $query .= ', ' . $this->_params['soft_expiration_field'] . ' = ?';
            $values[] = $this->_calc_expiration('soft');
        }
        if (!empty($this->_params['hard_expiration_field'])) {
            $query .= ', ' . $this->_params['hard_expiration_field'] . ' = ?';
            $values[] = $this->_calc_expiration('hard');
        }
        $query .= sprintf(' WHERE %s = ?', $this->_params['username_field']);
        $values[] = $userId;
        try {
            $this->_db->update($query, $values);
        } catch (Horde_Db_Exception $e) {
            throw new Horde_Auth_Exception($e);
        }
        return $password;
    }