Skip to content

FormLoginAuthenticator

Verifies a username/password login POST via a UserProviderInterface/PasswordHasherInterface pair.

A service the app’s own login endpoint/action calls directly — the framework ships no login page or form-rendering logic, only this verification step — but it also implements AuthenticatorInterface so it can sit in a firewall’s authenticator chain and be matched by supports() against the configured login-check path.

packages/csrf and packages/ratelimit are soft dependencies: pass a CsrfManager/LoginThrottle instance to enable CSRF verification / brute-force throttling, or omit them to skip both.

final class FormLoginAuthenticator implements AuthenticatorInterface

ImplementsAuthenticatorInterface
Since1.0.0
SourceAuthenticator/FormLoginAuthenticator.php

public function __construct(UserProviderInterface $userProvider, PasswordHasherInterface $passwordHasher, string $checkPath = '/login', string $identifierField = 'username', string $passwordField = 'password', ?CsrfManager $csrf = null, ?LoginThrottle $throttle = null): mixed

When given, failed attempts are throttled per identifier (see packages/ratelimit).

ParameterTypeDescription
$userProviderUserProviderInterfaceResolves the submitted identifier field to an identity.
$passwordHasherPasswordHasherInterfaceVerifies the submitted password against the identity’s stored hash.
$checkPathstringThe path a login POST is submitted to (matched by supports()).
$identifierFieldstringThe form field name holding the username/email.
$passwordFieldstringThe form field name holding the password.
$csrf?CsrfManagerWhen given, the submitted CSRF token is validated (see packages/csrf).
$throttle?LoginThrottleWhen given, failed attempts are throttled per identifier (see packages/ratelimit).

Returns mixed

MethodDescription
authenticate(ServerRequestInterface $request): Passport
onFailure(AuthenticationException $exception): null
supports(ServerRequestInterface $request): bool

public function authenticate(ServerRequestInterface $request): Passport

The incoming login POST request.

ParameterTypeDescription
$requestServerRequestInterfaceThe incoming login POST request.

Returns Passport — The resolved identity, session-backed (not stateless).

ThrowsWhen
AuthenticationExceptionIf the form data, CSRF token, or credentials are missing/invalid, or the throttle is exhausted.

public function onFailure(AuthenticationException $exception): null

The exception thrown by authenticate().

ParameterTypeDescription
$exceptionAuthenticationExceptionThe exception thrown by authenticate().

Returns null — Always null: defers to the firewall’s LoginRedirectEntryPoint.

public function supports(ServerRequestInterface $request): bool

The incoming request.

ParameterTypeDescription
$requestServerRequestInterfaceThe incoming request.

Returns bool — True if $request is a POST to the configured login-check path, otherwise false.