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;

Comments

Submitted by Prem Suthar (not verified) on Thu, 02/10/2022 - 09:31 Permalink

i want to skip the validation on reset password form in that user name check validation i want to skip and just simply print one message when user correct the send email and display the We've emailed you instructions for setting your password, if an account exists with the email you entered. You should receive them shortly if not correct the also same for security purpose.
Add new comment

Restricted HTML

Riadh Rahmi

Senior Web Developer (Drupal & Laravel)

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

Web Posts

Search

Page Facebook