interface Hasher

Defines the contract for hashing and verifying values, typically user passwords. Implementations wrap a specific hashing algorithm (e.g.

bcrypt or Argon2) behind a common interface so that callers hash and verify without depending on the underlying algorithm. This keeps the choice of algorithm and its parameters in a single place and allows it to be changed or upgraded without altering calling code.

Methods

string
make(string $value)

Hashes the given plain-text value.

bool
needsRehash(string $hashed)

Determines whether a previously computed hash should be re-created, for example because the algorithm's configured cost or parameters have since changed. Typically checked after a successful verify() so an out-of-date hash can be transparently upgraded.

bool
verify(string $value, string $hashed)

Verifies that a plain-text value matches a previously computed hash.

Details

at line 20
string make(string $value)

Hashes the given plain-text value.

Parameters

string $value

The plain-text value to hash.

Return Value

string

The resulting hash, suitable for storage.

at line 32
bool needsRehash(string $hashed)

Determines whether a previously computed hash should be re-created, for example because the algorithm's configured cost or parameters have since changed. Typically checked after a successful verify() so an out-of-date hash can be transparently upgraded.

Parameters

string $hashed

The existing hash to examine.

Return Value

bool

True if the value should be re-hashed with the current settings, otherwise false.

at line 41
bool verify(string $value, string $hashed)

Verifies that a plain-text value matches a previously computed hash.

Parameters

string $value

The plain-text value to check.

string $hashed

The hash to check against.

Return Value

bool

True if the value matches the hash, otherwise false.