Neos\Flow\Security\AccountRepository::findActiveByAccountIdentifierAndAuthenticationProviderName PHP Method

findActiveByAccountIdentifierAndAuthenticationProviderName() public method

Returns the account for a specific authentication provider with the given identifier if it's not expired
public findActiveByAccountIdentifierAndAuthenticationProviderName ( string $accountIdentifier, string $authenticationProviderName ) : Account
$accountIdentifier string The account identifier
$authenticationProviderName string The authentication provider name
return Account
    public function findActiveByAccountIdentifierAndAuthenticationProviderName($accountIdentifier, $authenticationProviderName)
    {
        $query = $this->createQuery();
        return $query->matching($query->logicalAnd($query->equals('accountIdentifier', $accountIdentifier), $query->equals('authenticationProviderName', $authenticationProviderName), $query->logicalOr($query->equals('expirationDate', null), $query->greaterThan('expirationDate', new \DateTime()))))->execute()->getFirst();
    }

Usage Example

 /**
  * @test
  */
 public function authenticationWithCorrectCredentialsResetsFailedAuthenticationCount()
 {
     $this->authenticationToken->_set('credentials', ['username' => 'username', 'password' => 'wrongPW']);
     $this->persistedUsernamePasswordProvider->authenticate($this->authenticationToken);
     $account = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName('username', 'myTestProvider');
     $this->assertEquals(1, $account->getFailedAuthenticationCount());
     $this->authenticationToken->_set('credentials', ['username' => 'username', 'password' => 'password']);
     $this->persistedUsernamePasswordProvider->authenticate($this->authenticationToken);
     $account = $this->accountRepository->findActiveByAccountIdentifierAndAuthenticationProviderName('username', 'myTestProvider');
     $this->assertEquals((new \DateTime())->format(\DateTime::W3C), $account->getLastSuccessfulAuthenticationDate()->format(\DateTime::W3C));
     $this->assertEquals(0, $account->getFailedAuthenticationCount());
 }