n How to change the user password reset link timeout in Drupal 8 & 9 | CodimTh

Please Disable Your Browser Adblock Extension for our site and Refresh This Page!

our ads are user friendly, we do not serve popup ads. We serve responsible ads!

Refresh Page
Skip to main content
On . By CodimTh
Category:

Example how to change the user password reset link timeout in Drupal 8 & 9.

<?php

/**
 * @file
 * Presents a UI element to set the user password reset link timeout.
 */

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter().
 *
 * Add the password reset link timeout setting on the user settings page.
 *
 * @see \Drupal\user\AccountSettingsForm
 */
function user_pwreset_timeout_form_user_admin_settings_alter(&$form, FormStateInterface $form_state) {
  $config = \Drupal::configFactory()->getEditable('user.settings');

  $form['password_timeout_settings'] = array(
    '#type' => 'details',
    '#title' => t('Password reset timeout'),
    '#open' => TRUE,
    '#weight' => 0,
  );
  $form['password_timeout_settings']['password_reset_timeout'] = [
    '#type' => 'number',
    '#min' => 1,
    '#max' => 31536000,
    '#title' => t('Password Reset Timeout'),
    '#description' => t('Set the timeout in seconds for one-time login links. The default is 86400 seconds (24 hours).'),
    '#default_value' => $config->get('password_reset_timeout', 86400),
  ];
  // Add submit handler to save password_reset_timeout configuration.
  $form['#submit'][] = 'user_pwreset_timeout_user_admin_settings_submit';
}

/**
 * Form submission handler for user_admin_settings().
 *
 * @see user_pwreset_timeout_form_user_admin_settings_alter()
 */
function user_pwreset_timeout_user_admin_settings_submit($form, FormStateInterface $form_state) {
  $timeout_value = $form_state->getValue('password_reset_timeout');
  $config = \Drupal::configFactory()->getEditable('user.settings');
  $config->set('password_reset_timeout', $timeout_value)->save();
}

 

Example 2 how to change the user password reset link timeout in settings.php file:

$conf['user.settings']['password_reset_timeout'] = 86400;

Riadh Rahmi

Senior Web Developer PHP/Drupal & Laravel

I am a senior web developer, I have experience in planning and developing large scale dynamic web solutions especially in Drupal & Laravel.

Web Posts

Search

Page Facebook