Change record status: 
Project: 
Introduced in branch: 
11.4.x
Introduced in version: 
11.4.0
Description: 

Functions related to one time authentication are deprecated in Drupal 11.4.0 and removed from Drupal 13.0.0. Use the methods on \Drupal\user\OneTimeAuthentication instead.

Deprecated Replacement
user_pass_rehash(): string \Drupal\user\OneTimeAuthentication::generateHmac(): \Drupal\Core\Url
user_cancel_url(): string \Drupal\user\OneTimeAuthentication::generateCancelConfirmUrl(): \Drupal\Core\Url
user_pass_reset_url(): string \Drupal\user\OneTimeAuthentication::generateOneTimeLoginUrl(): \Drupal\Core\Url
user_mail_tokens(): string \Drupal\user\OneTimeAuthentication::tokens(): \Drupal\Core\Url

The following protected helper functions are deprecated in Drupal 11.4.0 and removed from Drupal 12.0.0.

Deprecated Replacement
\Drupal\user\Controller\UserController::validatePathParameters() \Drupal\user\OneTimeAuthentication::verifyHmac()
\Drupal\Core\Command\ServerCommand::getOneTimeLoginUrl() -

Example 1

Before

$href = user_cancel_url($account);

After

$oneTimeAuthentication = \Drupal->service(OneTimeAuthentication::class);
$href = $oneTimeAuthentication->generateCancelConfirmUrl($account)->toString();

Example 2

Before

  #[Hook('mail')]
  public function mail($key, &$message, $params): void {
    [...]
    $options = [
      'langcode' => $langcode,
      'callback' => 'user_mail_tokens',
      'clear' => TRUE,
    ];
    $message['body'][] = $token_service->replacePlain($body, $context, $options);
    [...]
  }

After

  #[Hook('mail')]
  public function mail($key, &$message, $params): void {
    [...]
    $options = [
      'langcode' => $langcode,
      'callback' => \Drupal::service(OneTimeAuthentication::class)->tokens(...),
      'clear' => TRUE,
    ];
    $message['body'][] = $token_service->replacePlain($body, $context, $options);
    [...]
  }
Impacts: 
Module developers