2

There are a lot of answers on how to log in as a specific user. But I can't find any answer on how to check if the username and password is valid without logging in. I want to be able to do something like this:

$username = "bla@bla.com"
$password = "blablabla"

$valid = checkIfValidDetails($username, $password);

I simply want $valid = true if the username and password is correct, and false if not.

How can I do that?

0
3

Drupal 6 and 7

user_authenticate($username, $password);

Drupal 8

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

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.