Skip to main content

Password reset

Laravel's password broker refuses two kinds of request, and Fortify passes both refusals on:

RequestFortify 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, and it is written while the broker resets, before the token is deleted. 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.

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.