1.20.x user.module user_authenticate($name, $password)

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.:

File

modules/user/user.module, line 1906
Enables the user registration and login system.

Code

function user_authenticate($name, $password) {
  $uid = FALSE;
  if (!empty($name) && strlen(trim($password)) > 0) {
    $account = user_load_by_name($name);
    if ($account) {
      // Allow alternate password hashing schemes.
      require_once BACKDROP_ROOT . '/' . settings_get('password_inc', 'core/includes/password.inc');
      if (user_check_password($password, $account)) {
        // Successful authentication.
        $uid = $account->uid;

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