Framework Reference
Password Hashing
Staff (auth) and customer-portal (customer_accounts) passwords are hashed through one service, passwordHasher. By default it uses bcrypt with cost 10, exactly as earlier versions did. You can opt into Argon2id, the algorithm the OWASP Password Storage Cheat Sheet recommends, without forcing anyone to reset a password.
Configuration
| Variable | Default | Meaning |
|---|---|---|
OM_PASSWORD_HASH | bcrypt | bcrypt or argon2id. Any other value logs a warning and falls back to bcrypt. |
OM_PASSWORD_ARGON2_MEMORY_KIB | 19456 | Argon2id memory cost in KiB (19 MiB). |
OM_PASSWORD_ARGON2_TIME_COST | 2 | Argon2id iterations. |
OM_PASSWORD_ARGON2_PARALLELISM | 1 | Argon2id lanes. |
OM_PASSWORD_ARGON2_MAX_CONCURRENCY | 4 | Argon2 operations allowed to run at once in one process. |
OM_PASSWORD_ARGON2_MAX_QUEUE | 64 | Argon2 operations allowed to wait for a slot before new login attempts are refused with 503 and Retry-After. |
OM_PASSWORD_ARGON2_LEGACY_VERIFY | false | Keeps verifying stored Argon2id hashes while OM_PASSWORD_HASH=bcrypt. See Rolling back to bcrypt. |
The values are read once per process; restart the app and workers after changing them. The Argon2id defaults are the OWASP minimum. Values below those memory and iteration minimums, malformed values, and out-of-range values fall back to the safe defaults. Raise memory or iterations if your servers can afford a slower login.
How migration works
- Every stored hash says which algorithm made it (
$2a$,$2b$,$2y$for bcrypt,$argon2id$for Argon2id). Verification picks the algorithm from the hash, so both kinds keep working whichever algorithm is configured — except that after rolling back tobcryptthe stored Argon2id hashes needOM_PASSWORD_ARGON2_LEGACY_VERIFYor a password reset (see below). OM_PASSWORD_HASHdecides how new passwords are hashed: sign-up, invitations, user creation, password change and reset,mercato auth add-userandmercato auth set-password.- After a successful staff or portal login, a hash made with another algorithm, or with other Argon2id parameters, is replaced with a fresh one. The update only applies when the stored hash has not changed in the meantime, so a concurrent password change always wins. If the update fails, the error is logged and reported and the login still succeeds.
- With the default
bcrypt, bcrypt hashes are never rewritten, so the database is not touched on login.
Switching back from argon2id to bcrypt needs one more decision, because a bcrypt-only process must not load Argon2 for some accounts and not others.
Rolling back to bcrypt
With OM_PASSWORD_HASH=bcrypt and the default OM_PASSWORD_ARGON2_LEGACY_VERIFY=false, a stored Argon2id hash does not verify: those users cannot log in until their password is reset. This keeps the check profile identical for every outcome — one bcrypt comparison, whether the account exists, holds a bcrypt hash, holds an Argon2id hash or has no account at all — so response latency never reveals whether an account exists. The process logs one warning the first time it rejects an Argon2id hash.
Choose one of these when you roll back:
- Reset the affected passwords (invite users to reset, or set them with
mercato auth set-password). The uniform bcrypt profile stays in place. - Set
OM_PASSWORD_ARGON2_LEGACY_VERIFY=trueto keep verifying Argon2id hashes. Argon2 then joins the work profile for every outcome — including unknown accounts — so latency stays uniform, at the cost of one Argon2id operation per login attempt in that process. Argon2id hashes are still re-hashed to bcrypt after a successful login, so this is a migration window, not a permanent setting.
Before you switch
- Downgrades. Open Mercato versions released before this service can only verify bcrypt. Before downgrading, set
OM_PASSWORD_HASH=bcryptandOM_PASSWORD_ARGON2_LEGACY_VERIFY=trueon a version that supports both options. Each successful login converts that user’s stored Argon2id hash to bcrypt. Reset the passwords of users whose Argon2id hashes remain before downgrading. - Timing. Every password check spends the same work whatever the outcome — a correct password, a wrong one, an unknown account, or an account rejected after the check (deactivated, unverified, locked). With
bcryptthat is one bcrypt comparison and Argon2 is never loaded; an Argon2id hash is rejected under the same bcrypt floor unlessOM_PASSWORD_ARGON2_LEGACY_VERIFY=trueputs Argon2 into the profile. Withargon2idit is one bcrypt comparison plus one Argon2id verification, so accounts not yet migrated from bcrypt look the same as migrated ones. - Memory. Each Argon2id operation uses
OM_PASSWORD_ARGON2_MEMORY_KIBof memory. At mostOM_PASSWORD_ARGON2_MAX_CONCURRENCYrun at once per process, so peak Argon2 memory is aboutmemory × concurrency(76 MiB with the defaults). Further operations wait in a queue ofOM_PASSWORD_ARGON2_MAX_QUEUE; once it is full, login answers503withRetry-After: 1and the same generic message. - Platform. Argon2id uses the
@node-rs/argon2package, with prebuilt binaries for Linux (glibc and musl, x64 and arm64), macOS and Windows. It is loaded lazily, only when Argon2id is configured orOM_PASSWORD_ARGON2_LEGACY_VERIFY=truekeeps legacy hashes verifiable.
Scope
Only user and customer-portal passwords use this service. API keys, MFA one-time and recovery codes, SCIM tokens, checkout link passwords and agent client secrets are random secrets, not user-chosen passwords, and keep their own bcrypt hashing.
Custom hasher
The hasher implements hash(password), verify(password, storedHash), needsRehash(storedHash) and equalizeTiming(password). To plug in your own, call setPasswordHasher() from @open-mercato/shared/lib/auth/passwordHasher during app bootstrap (for example in your app's di.ts). The passwordHasher DI registration always resolves the active instance.