Password reset and change
Reset
passwordReset adds the forgotten password flow. It needs messages and links, and the users (findAccount, findByEmail, setPasswordHash, markEmailVerified) and tokens (with invalidate) stores, plus the methods that claim an unverified account in the other stores the data provider defines (see Magic link).
/auth/password/forgotsends apassword_resetlink to the address of an account, and answers the same for an unknown address: such a request waits for the running average time of the requests for known addresses. A new link invalidates the previous ones.3requests per hour per address and10per IP address (rateLimits.emailRequests).- A link is bound to the address it was sent to: after an email change, it answers
400 INVALID_TOKEN. /auth/password/resetchecks the password policy first:400 WEAK_PASSWORDleaves the link usable. Then it consumes the link, sets the hash (users.setPasswordHash()), revokes every session of the user (password_reset, withrevokeSessions, the default), and sendspassword_changed.- An unknown, expired or used link answers
400 INVALID_TOKEN;10checks per 15 minutes per IP address (rateLimits.tokenChecks). /auth/password/forgotanswers403 SSO_REQUIRED, withdata.connectionId, for an address of a domain that logs in with its IdP (SSO enforcement).- With
mode: 'cookie',/auth/password/resetfrom an untrusted origin answers403 CROSS_ORIGIN_REQUEST(see CSRF). - A reset invalidates every pending link and challenge of the account: email verification, password reset, email change, magic link, handoff code and MFA challenge.
- Events:
password.reset_requested(existing accounts only),password.resetandpassword.changed(via: 'reset').
Unverified accounts
A reset link proves the address. On an unverified account, the reset first claims it for the owner of the address, like a magic link: the password, the passkeys, the linked provider accounts, the second factors, the recovery codes, the trusted devices and the sessions set before are removed, the address is verified (users.markEmailVerified()), and an account_claimed message is sent. The new password is set after.
Change
POST /auth/password/change is on when the data provider has users.setPasswordHash() (and users.findAccount()).
The other sessions of the user are revoked (password_changed); the current one stays, with the sessions store. Without it, sessions cannot be singled out: every session is revoked, the current one included. password_changed is sent when messages is set. A change or a reset revokes the trusted devices of the user, and invalidates its pending links and challenges.
rateLimits.stepUp counts the failures, with the peek() method of the rate limit store, under a ceiling of 30 attempts per 15 minutes: createAuth() rejects a store without peek(), unless rateLimits.stepUp.user counts attempts only.
Services
auth.passwordReset.request({ email }), auth.passwordReset.complete({ token, password }) and auth.passwords.change({ userId, currentPassword, newPassword, sessionId?, mfaVerifiedAt? }) do the same outside the routes.