How to manually check if a username and password is correct?
Drupal 6 and 7

user_authenticate($username, $password);


Drupal 8

// Inject user.auth service..
$uid = $this-&gt;userAuth-&gt;authenticate($username, $password);
// or
$uid = \Drupal::service('user.auth')-&gt;authenticate($username, $password);


Source: How to check logged in user username/password/role using Drupal function for validation