For AI agents: the complete documentation index is available at https://dotpress.dev/llms.txt, the full documentation bundle is available at https://dotpress.dev/llms-full.txt, and this page is available as Markdown at https://dotpress.dev/auth/password-reset.md.

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).

passwordReset: {
  ttl: '1h', // lifetime of the links
  revokeSessions: true, // revoke every session of the user
  autoLogin: false, // start a session after the reset
},
RouteBodyAnswer
POST /auth/password/forgot{ email, redirectTo? }202 { status: 'accepted' }, always
POST /auth/password/reset{ token, password, mode? }200 { status: 'password_reset' }, plus the tokens with autoLogin
  • /auth/password/forgot sends a password_reset link 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. 3 requests per hour per address and 10 per 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/reset checks the password policy first: 400 WEAK_PASSWORD leaves the link usable. Then it consumes the link, sets the hash (users.setPasswordHash()), revokes every session of the user (password_reset, with revokeSessions, the default), and sends password_changed.
  • An unknown, expired or used link answers 400 INVALID_TOKEN; 10 checks per 15 minutes per IP address (rateLimits.tokenChecks).
  • /auth/password/forgot answers 403 SSO_REQUIRED, with data.connectionId, for an address of a domain that logs in with its IdP (SSO enforcement).
  • With mode: 'cookie', /auth/password/reset from an untrusted origin answers 403 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.reset and password.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()).

POST /auth/password/change
Authorization: Bearer …
{ "currentPassword": "…", "newPassword": "…" }

200 { "status": "password_changed" }
AnswerWhen
401 INVALID_PASSWORDWrong current password. 10 failures per 15 minutes per user (rateLimits.stepUp.user), then 429 TOO_MANY_REQUESTS.
400 WEAK_PASSWORDAgainst the policy, or rule: 'same_as_current'
409 PASSWORD_NOT_SETAn account without password (SSO)
403 IMPERSONATION_FORBIDDENAn impersonation session
403 MFA_REQUIREDWith mfa, a user with factors or passkeys without a second factor in the last 10 minutes (password.changeRequiresMfa)

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.