Login to external server from Drupal site Is there any way to customize Drupal login to use authentication from an external server?

I'd like to know about any modules or if Drupal core can implement this function.

Source code:
                                                                                       

// Include FirePHP for debug

function authdave_form_alter(&amp;$form, &amp;$form_state, $form_id) {
    // Authentication based on username and password
    if ( ($form_id == 'user_login' || $form_id == 'user_login_block') ) {
        $form['#validate'][] = 'authdave_user_form_validate';
    }
}
/**
* Custom form validation function
*/
function authdave_user_form_validate($form, &amp;$form_state) {
    if( !authdave_authenticate($form_state) ) {
        form_set_error('name', t('Unrecognize username.'));
    }
}
/**
* Custom user authentication function
*/
function authdave_authenticate($form_state) {
    // get first four characters from user name
    $complete_username = $form_state['input']['name'];
    $password = $form_state['input']['pass'];

    // retrieve users credentials from DB
    $credential = get_all_credentials();

    while($row = $credential-&gt;fetch_assoc()) {
        // check if there are any match
        if ( $row["username"] ==  $complete_username &amp;&amp; $row["password"] == $password) {
            user_external_login_register($complete_username, 'custom_athentication');
            return TRUE;
        }
    }

    return FALSE;

}

function get_all_credentials() {

    //credenziali di accesso al dbms
    $server = "****";
    $username = "***";
    $password = "***";

    //nome db
    $db_name = "credenziali_db";

    //creo una connessione con il dbms
    $conn = new mysqli($server, $username, $password, $db_name);

    if ($conn -&gt; connect_error) {
        die("Connection failed: " . $conn-&gt;connect_error);
    }

    echo "Connection successfully";

    //sql query
    $sql = "SELECT username, password FROM credenziali";
    $result = $conn -&gt; query($sql); //risultato della query

    return $result;

}


?>
This depends what you mean by external server? There's a tonne of contribution modules at the moment that support a variety of external logins.

You can implement Open Auth 2 to allow a single sign on:

https://www.drupal.org/project/oauth2_authentication


Or you can use Facebooks Oauth authentication: 

https://www.drupal.org/project/fboauth