Password reset
The reset-link request
Laravel's password broker refuses two kinds of request, and Fortify passes both refusals on:
| Request | Fortify on its own |
|---|---|
| an address without an account | "We can't find a user with that email address." |
| an address that asked for a link a moment ago | "Please wait before retrying." |
Only an address with an account can have asked a moment ago, so both refusals say that the account
exists. The package answers each of them with the response your application gives for a link that
was sent, with Laravel's "We have emailed your password reset link." On a web form that is a
redirect back with the message flashed as status, and for a JSON request it is the same body with
200 OK. If you bound your own SuccessfulPasswordResetLinkRequestResponse, that is the one the
refusals receive.
The broker still mails only an address that has an account, and only once within its throttle. A malformed address is still refused by Fortify's validation, which depends on the input alone.
The reset
Fortify's reset fails with "We can't find a user with that email address." for an unknown address
and with "This password reset token is invalid." for a known address whose token is wrong or has
expired. The package answers every failed reset with the second one: on a web form a redirect back
with the error on the email field, and for a JSON request a 422 with the same error. A reset
with the right token goes through as before.
A form sent twice
A double click sends the reset form twice. The first request sets the password and uses the token up, so the second finds no token. Where that second request repeats a reset the same session completed within the last minute, it receives the answer of a reset that went through: the same address, a password its confirmation agrees with, and the password the account now holds. Any other refused reset keeps the invalid-token answer, so the answer tells nobody anything about an account they did not just reset themselves.
The account is read where the broker Fortify resets with reads it. A broker of your own in front of
Laravel's, one that sends the reset mail from the queue for instance, works as well: where it does not
offer getUser(), the account comes from the user provider auth.passwords.<broker>.provider names,
which is where Laravel's broker looks.
The note is kept in your application's cache for a minute, under a hash of the session and the address of the form keyed with the application key, and it is written while the broker resets, before the token is deleted. A session kept in Redis, Memcached or DynamoDB stands in the cache under its id, so a plain hash of the two could be matched against a guessed address by whoever reads the cache keys. A cache store that every web server of the application shares, as a database or Redis store is, lets the second request find the note whichever server takes it.
The note is kept in the default store, and a store that loses it within its minute answers the
second request with the invalid-token answer, although the password the person chose is set and
signs them in. A store loses it the way it loses the count of the
mail budget: by eviction under memory pressure, by a
cache:clear or optimize:clear, or by a restart without persistence. A database store keeps the
row of every note it was given until the
pruning of expired keys deletes it.
A refused reset looks for the note before it reads any account. Its answer comes after the broker's minimum duration has ended, so reading the account of an address that has one would make that answer later. In a session that has not just reset the address of its form, the answer reads one cache entry and no account, for an address with an account and for one without alike.
Switching one off
Each of the two has its own switch, in case your application answers it in a way of its own:
FORTIFY_HARDENING_PASSWORD_RESET_LINK=false
FORTIFY_HARDENING_PASSWORD_RESET=false
The difference in time on these routes is covered in Timing.