Same name and namespace in other branches
  1. 4.7.x modules/user.module \user_pass_reset_url()
  2. 5.x modules/user/user.module \user_pass_reset_url()
  3. 6.x modules/user/user.module \user_pass_reset_url()
  4. 7.x modules/user/user.module \user_pass_reset_url()
  5. 8.9.x core/modules/user/user.module \user_pass_reset_url()
  6. 9 core/modules/user/user.module \user_pass_reset_url()

Generates a unique URL for a user to log in and reset their password.

Parameters

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

array $options: (optional) A keyed array of settings. Supported options are:

  • langcode: A language code to be used when generating locale-sensitive URLs. If langcode is NULL the users preferred language is used.

Return value

string A unique URL that provides a one-time log in for the user, from which they can change their password.

6 calls to user_pass_reset_url()
ServerCommand::getOneTimeLoginUrl in core/lib/Drupal/Core/Command/ServerCommand.php
Gets a one time login URL for user 1.
TestSiteUserLoginCommand::execute in core/tests/Drupal/TestSite/Commands/TestSiteUserLoginCommand.php
UserPasswordResetTest::testResetImpersonation in core/modules/user/tests/src/Functional/UserPasswordResetTest.php
Make sure that users cannot forge password reset URLs of other users.
UserRegistrationTest::testRegistrationWithEmailVerification in core/modules/user/tests/src/Functional/UserRegistrationTest.php
UserTokenReplaceTest::testUserTokenReplacement in core/modules/user/tests/src/Functional/UserTokenReplaceTest.php
Creates a user, then tests the tokens generated from it.

... See full list

File

core/modules/user/user.module, line 523
Enables the user registration and login system.

Code

function user_pass_reset_url($account, $options = []) {
  $timestamp = \Drupal::time()
    ->getRequestTime();
  $langcode = $options['langcode'] ?? $account
    ->getPreferredLangcode();
  return Url::fromRoute('user.reset', [
    'uid' => $account
      ->id(),
    'timestamp' => $timestamp,
    'hash' => user_pass_rehash($account, $timestamp),
  ], [
    'absolute' => TRUE,
    'language' => \Drupal::languageManager()
      ->getLanguage($langcode),
  ])
    ->toString();
}