Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. user.module

function user_pass_rehash

Creates a unique hash value for use in time-dependent per-user URLs.

This hash is normally used to build a unique and secure URL that is sent to the user by email for purposes such as resetting the user's password. In order to validate the URL, the same hash can be generated again, from the same information, and compared to the hash value from the URL. The hash contains the time stamp, the user's last login time, the numeric user ID, and the user's email address. For a usage example, see user_cancel_url() and \Drupal\user\Controller\UserController::confirmCancel().

Parameters

\Drupal\user\UserInterface $account: An object containing the user account.

int $timestamp: A UNIX timestamp, typically \Drupal::time()->getRequestTime().

Return value

string A string that is safe for use in URLs and SQL statements.

1 call to user_pass_rehash()
UserController::validatePathParameters in core/modules/user/src/Controller/UserController.php
Validates hash and timestamp.

File

core/modules/user/user.module, line 318

Code

function user_pass_rehash(UserInterface $account, $timestamp) {
    $data = $timestamp;
    $data .= ':' . $account->getLastLoginTime();
    $data .= ':' . $account->id();
    $data .= ':' . $account->getEmail();
    return Crypt::hmacBase64($data, Settings::getHashSalt() . $account->getPassword());
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal