hook_auth

Definition

hook_auth($username, $password, $server)
developer/hooks/authentication.php, line 38

Description

Verify authentication of a user.

The _auth hook is the heart of any authentication module. This function is called whenever a user is attempting to log in using your authentication module. The module uses this information to allow or deny access to the site.

Parameters

$username The substring before the final '@' character in the username field.

$password The whole string submitted by the user in the password field.

$server The substring after the final '@' symbol in the username field.

Return value

For successful authentications, this function returns TRUE. Otherwise, it returns FALSE.

Related topics

Namesort iconDescription
HooksAllow modules to interact with the Drupal core.

Code

<?php
function hook_auth($username, $password, $server) {
  if (variable_get('drupal_authentication_service', 0)) {
    if (!$server) {
      $server = variable_get('drupal_default_da_server', '');
    }
    else if (variable_get('drupal_default_da_server_only', 0)) {
      if (variable_get('drupal_default_da_server', '') != $server) {
        return;
      }
    }
    if (!empty($server)) {
      $result = xmlrpc("http://$server/xmlrpc.php", 'drupal.login', $username, $password);
      if ($result === FALSE) {
        drupal_set_message(t('Error %code: %message', array('%code' => xmlrpc_errno(), '%message' => xmlrpc_error_msg())), 'error');
      }
      else {
        return $result;
      }
    }
  }
}
?>
 
 

Drupal is a registered trademark of Dries Buytaert.