API / Minn\Auth / PasswordReset

PasswordReset final readonly class

Minn\Auth\PasswordReset · public/minn/src/Minn/Auth/PasswordReset.php · 78 lines

Password reset keys in the reference's storage shape: user_activation_key holds "time:hash", the key itself travels in the email link and is good for a day. The hash is the reference's own ($generic$, FastHash), so a link either stack sent works on the other. Older shapes still verify: a phpass hash (WordPress before 6.8) and the engine's former $minn$ HMAC. A matching key stored without its time (or, older still, stored as itself) is expired, as the reference treats it.

Constants and properties

constLIFETIME = 86400
privatereadonly Minn\Content\Users $users

Promoted from the constructor.

Public

new__construct(Minn\Content\Users $users)#
methodissue(Minn\Content\UserRecord $user): string#

Mints a key, stores its hash, returns the key for the link.

staticmint(): array#

A new key and the value that stores it (the time it was issued and its hash), for a caller that saves it itself.

@return array{0: string, 1: string}
methodverify(Minn\Content\UserRecord $user, string $key): bool#

True when the key matches the stored hash and has not expired: a day, or what password_reset_expiration makes it.

methodstatus(Minn\Content\UserRecord $user, string $key, int $lifetime = self::LIFETIME): string#

"valid", "expired" (a matching key past its lifetime, a day unless given), "unstamped" (a matching key stored without a time, which the reference counts expired after asking password_reset_key_expired), or "invalid".

methodclear(Minn\Content\UserRecord $user): void#

Forgets a user's reset key.

Internals 2

Private and protected methods: how the class does its work. Not a contract; they change whenever the code is tidied.

privatehash(string $key): string#

The stored hash for a new key: the reference's own, or phpass (which it also reads) without sodium.

privatematches(string $key, string $hash): bool#