Chris@0: 'entity.manager']; Chris@18: Chris@18: /** Chris@18: * The entity type manager. Chris@0: * Chris@18: * @var \Drupal\Core\Entity\EntityTypeManagerInterface Chris@0: */ Chris@18: protected $entityTypeManager; Chris@0: Chris@0: /** Chris@0: * The password hashing service. Chris@0: * Chris@0: * @var \Drupal\Core\Password\PasswordInterface Chris@0: */ Chris@0: protected $passwordChecker; Chris@0: Chris@0: /** Chris@0: * Constructs a UserAuth object. Chris@0: * Chris@18: * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager Chris@18: * The entity type manager. Chris@0: * @param \Drupal\Core\Password\PasswordInterface $password_checker Chris@0: * The password service. Chris@0: */ Chris@18: public function __construct(EntityTypeManagerInterface $entity_type_manager, PasswordInterface $password_checker) { Chris@18: $this->entityTypeManager = $entity_type_manager; Chris@0: $this->passwordChecker = $password_checker; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function authenticate($username, $password) { Chris@0: $uid = FALSE; Chris@0: Chris@0: if (!empty($username) && strlen($password) > 0) { Chris@18: $account_search = $this->entityTypeManager->getStorage('user')->loadByProperties(['name' => $username]); Chris@0: Chris@0: if ($account = reset($account_search)) { Chris@0: if ($this->passwordChecker->check($password, $account->getPassword())) { Chris@0: // Successful authentication. Chris@0: $uid = $account->id(); Chris@0: Chris@0: // Update user to new password scheme if needed. Chris@0: if ($this->passwordChecker->needsRehash($account->getPassword())) { Chris@0: $account->setPassword($password); Chris@0: $account->save(); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: Chris@0: return $uid; Chris@0: } Chris@0: Chris@0: }