UserAuth.php in Drupal 9
File
core/modules/user/src/UserAuth.php
View source
<?php
namespace Drupal\user;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Password\PasswordInterface;
class UserAuth implements UserAuthInterface {
protected $entityTypeManager;
protected $passwordChecker;
public function __construct(EntityTypeManagerInterface $entity_type_manager, PasswordInterface $password_checker) {
$this->entityTypeManager = $entity_type_manager;
$this->passwordChecker = $password_checker;
}
public function authenticate($username, $password) {
$uid = FALSE;
if (!empty($username) && strlen($password) > 0) {
$account_search = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'name' => $username,
]);
if ($account = reset($account_search)) {
if ($this->passwordChecker
->check($password, $account
->getPassword())) {
$uid = $account
->id();
if ($this->passwordChecker
->needsRehash($account
->getPassword())) {
$account
->setPassword($password);
$account
->save();
}
}
}
}
return $uid;
}
}
Classes
Name |
Description |
UserAuth |
Validates user authentication credentials. |