Make WordPress Core


Ignore:
Timestamp:
01/24/2009 10:38:19 PM (18 years ago)
Author:
westi
Message:

Make authentication more pluggable than ever before. See #8938 props wnorris.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/pluggable.php

    r10395 r10437  
    423423function wp_authenticate($username, $password) {
    424424        $username = sanitize_user($username);
    425 
    426         if ( '' == $username )
    427                 return new WP_Error('empty_username', __('<strong>ERROR</strong>: The username field is empty.'));
    428 
    429         if ( '' == $password )
    430                 return new WP_Error('empty_password', __('<strong>ERROR</strong>: The password field is empty.'));
    431 
    432         $user = get_userdatabylogin($username);
    433 
    434         if ( !$user || ($user->user_login != $username) ) {
    435                 do_action( 'wp_login_failed', $username );
    436                 return new WP_Error('invalid_username', __('<strong>ERROR</strong>: Invalid username.'));
    437         }
    438 
    439         $user = apply_filters('wp_authenticate_user', $user, $password);
    440         if ( is_wp_error($user) ) {
    441                 do_action( 'wp_login_failed', $username );
    442                 return $user;
    443         }
    444 
    445         if ( !wp_check_password($password, $user->user_pass, $user->ID) ) {
    446                 do_action( 'wp_login_failed', $username );
    447                 return new WP_Error('incorrect_password', __('<strong>ERROR</strong>: Incorrect password.'));
    448         }
    449 
    450         return new WP_User($user->ID);
     425        $password = trim($password);
     426
     427        $user = apply_filters('authenticate', null, $username, $password);
     428
     429        if ($user == null) {
     430                // TODO what should the error message be? (Or would these even happen?)
     431                // Only needed if all authentication handlers fail to return anything.
     432                $user = new WP_Error('authentication_failed', __('<strong>ERROR</strong>: Invalid username or incorrect password.'));
     433        }
     434
     435        if (is_wp_error($user)) {
     436                do_action('wp_login_failed', $username);
     437        }
     438
     439        return $user;
    451440}
    452441endif;
Note: See TracChangeset for help on using the changeset viewer.