Additional validation after successful login I want to implement some additional validation steps right after a user has logged in to a Drupal site.

So far, I have implemented the additional validation inside hook_user_login. If the validation fails, I am forcing the logout by calling user_logout.



EDIT: Part of the users are authenticated through an external SSO, so altering the login form to add an additional validation does not seem to be a good solution.



Is this the most standard way to do it, or is there a better way?
If You want to abort login I think You should try to add own validate function to user_login whith hook_form_alter (https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_alter/7)

&lt;?php
/**
 * Implements hook_form_alter().
 */
function MYMODULE_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  if ($form_id == 'user_login') { // or $form_id = 'user_login_form'
    $form['#validate'][] = 'check_username_against_ad_hoc_service';
  }
}

function check_username_against_ad_hoc_service($form, &amp;$form_state) {
  $name = $form_state['values']['name'];

  if($name == 'NoGo') {
    form_set_error('name', 'You're an Ad-hoc!');
  }
}
?&gt;


You can also use function hook_form_FORM_ID_alter (https://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_form_FORM_ID_alter/7)