1 Password Reset & First‐Login Forced Change
vBlackOut edited this page 2026-08-20 15:50:57 +02:00

Password Reset & First-Login Forced Change

This page covers two related flows that both end at the same place — a user setting a new password via POST /reset-password:

  1. Admin-triggered reset — proxyauth reset-password --username X emails a link.
  2. First-login forced change — an admin sets a temporary password (db-add-user --must-change-password); the user's next login redirects them straight to the change-password page instead of logging them in.

Both are built on the same single-use, time-limited token mechanism, stored in a dedicated local LMDB store independent of everything else ProxyAuth keeps in LMDB (token revocation, the database fallback cache).


Overview

flowchart TD
    subgraph trigger [" "]
        direction LR
        A(["proxyauth reset-password<br/>--username X"])
        B(["Login attempt<br/>must_change_password: true"])
    end

    A --> C[("reset::db LMDB<br/>single-use token store")]
    B --> C

    C --> D[/"Redirect or email link<br/>page_change_password?token=..."/]
    D --> E["User submits the form"]
    E --> F["POST /reset-password<br/>token · password · verif_password · csrf_token"]
    F --> G(["Password updated<br/>token consumed · effective immediately"])

    classDef trigger fill:#eef2ff,stroke:#4f46e5,stroke-width:1px,color:#1e1b4b
    classDef store fill:#fef3c7,stroke:#d97706,stroke-width:1px,color:#78350f
    classDef step fill:#f8fafc,stroke:#64748b,stroke-width:1px,color:#0f172a
    classDef done fill:#dcfce7,stroke:#16a34a,stroke-width:1px,color:#14532d

    class A,B trigger
    class C store
    class D,E,F step
    class G done

1. Admin-triggered reset

Command: proxyauth reset-password --username alice

Requires:

  • smtp configured in config.json
  • page_change_password configured in config.json
  • alice has an email on file (email in config.json, or the user_email table for a database-backed user)

All three are checked up front — see CLI Reference § proxyauth reset-password for what happens if one is missing.

On success, a single-use token valid for 1 hour is generated and emailed using the template at /etc/proxyauth/mail/templates/reset_password.txt (created automatically on first startup if smtp is configured). The link is page_change_password?token=<token>.

The user's current password keeps working until they actually complete the reset — this isn't a lockout, just a way back in.


2. First-login forced change

Set a temporary password and require the user to replace it before they can use the account normally:

proxyauth db-add-user --username bob --password "Temp-Password-123" --must-change-password

The next time bob logs in with that password (credentials, and TOTP if login_via_otp is enabled, are still checked normally), ProxyAuth doesn't issue a session. Instead:

  • A fresh single-use token is generated (same store, same 1-hour validity as the admin-reset flow).
  • If session_cookie: true (the normal browser flow): the response is 303 See Other, redirecting to page_change_password?token=.... The browser follows it automatically.
  • If session_cookie: false (an API/JSON client — nothing to redirect, a fetch/curl call won't follow a 303 the way a browser does): the response is 200 OK with a JSON body instead, so the client can act on it programmatically:
    {
      "must_change_password": true,
      "reset_link": "https://example.com/change-password?token=..."
    }
    

Either way, if page_change_password isn't configured, the login is refused outright with an error rather than silently letting a temporary password through:

Password change required, but no change-password page is configured — contact an administrator.

3. POST /reset-password — completing the change

This is the endpoint the page at page_change_password is expected to submit to. Accepts JSON or application/x-www-form-urlencoded, same dual-format handling as /auth.

Body:

Field Description
token The single-use token from the link/redirect.
password The new password.
verif_password Must match password exactly.
csrf_token Always required on this route, regardless of whether csrf_token is enabled for /auth — there's no scenario where skipping CSRF is acceptable on an endpoint that sets a password from an unauthenticated context.

password must be at least 12 characters — the only length/strength requirement enforced anywhere in ProxyAuth today (there's no charset/complexity policy beyond that floor). Shorter than that, or a mismatch with verif_password, gets a 400 before the token is even looked up.

Example:

curl -X POST https://example.com/reset-password \
  -H "Content-Type: application/json" \
  -d '{
    "token": "…",
    "password": "new-password",
    "verif_password": "new-password",
    "csrf_token": "…"
  }'

On success (200 OK):

{ "status": "ok" }

Possible errors:

Status Cause
400 password and verif_password don't match, password is shorter than 12 characters, invalid/missing CSRF token, or the token is invalid/expired
404 Unknown user (the token resolved to a username that no longer exists)
500 Database unreachable, or an internal error writing the new password — the response body is always a generic "Internal error updating password"; the real detail (which could include internal hostnames/ports) is logged server-side, never returned to the caller

What happens on success:

  1. The username is looked up first in file-based users, then the database (whichever they actually live in).
  2. The new password is hashed with Argon2 and written — to config.json for a file-based user, or the users table for a database-backed one.
  3. Takes effect immediately, no restart needed:
    • File-based users: reflected into AppState.password_overrides (the same hot-reload overlay pattern used for OTP resets — see TOTP Enrollment & Reset).
    • Database-backed users: the in-memory db_users snapshot is updated directly, without waiting for the next incremental scan tick.
  4. must_change_password is cleared automatically — a completed password change always satisfies it, regardless of which flow (admin reset or forced first-login) triggered it.
  5. The token is consumed — the same link can't be used twice.

The actual database write runs through spawn_blocking, same as the periodic background scan/purge tasks — a slow or unreachable database during a reset submission can't stall the whole service or block it from responding to a shutdown signal.


Token storage

Reset tokens live in their own local LMDB environment (/opt/proxyauth/db/password_reset/ by default, overridable via the PROXYAUTH_PASSWORD_RESET_PATH environment variable) — separate from the token-revocation LMDB store and the database fallback cache's LMDB store, so none of the three share state or have any startup-order dependency on each other.

The directory is created with 0700 permissions (owner-only) on Unix, set explicitly rather than left to whatever the process's umask happens to be — a token in this store is a bearer credential valid for up to an hour, so it shouldn't be readable by other local users on the same machine. The database fallback cache's LMDB directory gets the same treatment, since it mirrors the full user table including password hashes.

A background task purges expired tokens hourly. This runs unconditionally (not tied to databases being configured), since the reset flow works for file-based users too.


Emails per user

Each user can have more than one email address on file. In config.json:

"email": [
  { "address": "alice@example.com", "primary": true },
  { "address": "alice-personal@example.com", "primary": false }
]

For a database-backed user, the equivalent lives in the user_email table (user_id, email, is_primary) — set via db-add-user --email ... --primary-email ... (see CLI Reference).

When sending a reset link, ProxyAuth uses whichever entry is marked primary: true. If none is marked (or the data predates this field), it falls back to the first entry in the list.


See also