For Drupal 7: In your settings.php try adding this:
$conf['user_password_reset_timeout'] = '259200';
In Drupal 8, you need to add the following line to your settings.php file:
$config['user.settings']['password_reset_timeout'] = 259200;
One can do the same in Drupal 8 via Drush too.
To get the current setting by default it is 86400 sec means 1 day
drush config:get user.settings password_reset_timeout
To change the reset timeout duration for 2 weeks
drush config:set user.settings password_reset_timeout 1209600
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();
}