function user_authenticate

Try to validate the user's login credentials locally.

Parameters

$name: User name to authenticate.

$password: A plain-text password, such as trimmed text from form values.

Return value

The user's uid on success, or FALSE on failure to authenticate.

1 call to user_authenticate()
user_login_authenticate_validate in drupal/core/modules/user/user.module
A validate handler on the login form. Check supplied username/password against local users table. If successful, $form_state['uid'] is set to the matching user ID.

File

drupal/core/modules/user/user.module, line 1622
Enables the user registration and login system.

Code

function user_authenticate($name, $password) {
  $uid = FALSE;
  if (!empty($name) && !empty($password)) {
    $account = user_load_by_name($name);
    if ($account) {
      $password_hasher = drupal_container()
        ->get('password');
      if ($password_hasher
        ->check($password, $account)) {

        // Successful authentication.
        $uid = $account->uid;

        // Update user to new password scheme if needed.
        if ($password_hasher
          ->userNeedsNewHash($account)) {
          $account->pass = $password;
          $account
            ->save();
        }
      }
    }
  }
  return $uid;
}