PasswordResetToken
in package
One-time password reset token — shared by the user account and by adverts placed without an account.
The plain token travels only in the e-mailed link; the database keeps its sha256 hash and an expiry. Whoever reads the table (backup, SQL injection elsewhere) therefore cannot use a pending reset. The token is consumed by clearing both columns, so a used or replaced link never matches again.
Pure, no I/O — the managers own storage and delivery.
Table of Contents
Constants
- TTL_SECONDS : int = 3600
- Link validity.
Methods
- buildExpiry() : DateTime
- generate() : string
- 32 random bytes as hex (64 characters, 256 bits) — safe in a URL as is.
- hash() : string
- matches() : bool
- Does the plain token from the link match the stored hash and is it still valid?
Constants
TTL_SECONDS
Link validity.
public
int
TTL_SECONDS
= 3600
Methods
buildExpiry()
public
static buildExpiry(DateTimeInterface $now) : DateTime
Parameters
- $now : DateTimeInterface
Return values
DateTimegenerate()
32 random bytes as hex (64 characters, 256 bits) — safe in a URL as is.
public
static generate() : string
Return values
stringhash()
public
static hash(string $plainToken) : string
Parameters
- $plainToken : string
Return values
stringmatches()
Does the plain token from the link match the stored hash and is it still valid?
public
static matches(string $plainToken, string|null $storedHash, DateTimeInterface|null $expiresAt, DateTimeInterface $now) : bool
An empty stored hash (no reset pending, or already consumed) never matches, not even an
empty submitted token. The comparison is constant time (hash_equals).
Parameters
- $plainToken : string
- $storedHash : string|null
- $expiresAt : DateTimeInterface|null
- $now : DateTimeInterface