Skip to content

PasswordHasherInterface

Thin contract over PHP’s password_hash() family, so FormLoginAuthenticator/HttpBasicAuthenticator (both in the future packages/auth) depend on an interface rather than the global functions directly.

Default implementation: argon2id, bcrypt fallback.

interface PasswordHasherInterface

Implemented byDefaultPasswordHasher
Since1.0.0
SourceSecurity/Auth/PasswordHasherInterface.php
MethodDescription
hash(string $plaintext): string
needsRehash(string $hash): boolTrue if $hash was produced with weaker-than-current-default parameters (algorithm/cost) and should be re-hashed on next successful verify.
verify(string $plaintext, string $hash): bool

abstract public function hash(string $plaintext): string

The plaintext password to hash.

ParameterTypeDescription
$plaintextstringThe plaintext password to hash.

Returns string — The resulting hash, suitable for storage.

abstract public function needsRehash(string $hash): bool

True if $hash was produced with weaker-than-current-default parameters (algorithm/cost) and should be re-hashed on next successful verify.

A previously-stored hash (see hash()).

ParameterTypeDescription
$hashstringA previously-stored hash (see hash()).

Returns bool — True if $hash should be re-hashed, otherwise false.

abstract public function verify(string $plaintext, string $hash): bool

A previously-stored hash (see hash()).

ParameterTypeDescription
$plaintextstringThe plaintext password to check.
$hashstringA previously-stored hash (see hash()).

Returns bool — True if $plaintext matches $hash, otherwise false.