Skip to content

Instantly share code, notes, and snippets.

@baopham
Created May 25, 2012 22:46
Show Gist options
  • Save baopham/2790987 to your computer and use it in GitHub Desktop.
Save baopham/2790987 to your computer and use it in GitHub Desktop.
Drupal module to remove forgotten password link
<?php
// $Id$
/**
* @file
* Module to remove the forgotten password link
*/
/**
* Implementation of hook_menu_alter().
*/
function password_menu_alter(&$items) {
$items['user/password']['access callback'] = FALSE;
}
/**
* Implementation of hook_form_alter().
*/
function password_form_alter(&$form, $form_state, $form_id) {
if (($form_id == 'user_login_block' || $form_id == 'user_login')) {
$index = array_search('user_login_final_validate', $form['#validate']);
$form['#validate'][$index] = 'password_user_login_final_validate';
}
}
/**
* Remove forgotten password link in the error messages.
*/
function password_user_login_final_validate($form_id, &$form_state) {
if (empty($form_state['uid'])) {
// Always register an IP-based failed login event.
flood_register_event('failed_login_attempt_ip', variable_get('user_failed_login_ip_window', 3600));
// Register a per-user failed login event.
if (isset($form_state['flood_control_user_identifier'])) {
flood_register_event('failed_login_attempt_user', variable_get('user_failed_login_user_window', 21600), $form_state['flood_control_user_identifier']);
}
if (isset($form_state['flood_control_triggered'])) {
if ($form_state['flood_control_triggered'] == 'user') {
form_set_error('name', format_plural(variable_get('user_failed_login_user_limit', 5), 'Sorry, there has been more than one failed login attempt for this account. It is temporarily blocked. Try again later or <a href="@url">request a new password</a>.', 'Sorry, there have been more than @count failed login attempts for this account. It is temporarily blocked. Try again later.'));
}
else {
// We did not find a uid, so the limit is IP-based.
form_set_error('name', t('Sorry, too many failed login attempts from your IP address. This IP address is temporarily blocked. Try again later.'));
}
}
else {
form_set_error('name', t('Sorry, unrecognized username or password.'));
watchdog('user', 'Login attempt failed for %user.', array('%user' => $form_state['values']['name']));
}
}
elseif (isset($form_state['flood_control_user_identifier'])) {
// Clear past failures for this user so as not to block a user who might
// log in and out more than once in an hour.
flood_clear_event('failed_login_attempt_user', $form_state['flood_control_user_identifier']);
}
}
@deivamagalhaes
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment