Changelog - 2026-11-01
CredentialHelper hashes and checks passwords with Bun.password
New FeatureIn one line. CredentialHelper in @venizia/ignis-helpers hashes and verifies passwords using Bun.password without rehashing or migrating existing records.
What changed
- New class
CredentialHelper. It provides statichash({ password, algorithm?, cost? })andverify({ password, hash })methods. It requires Bun and throws on other runtimes. - Stored formats.
hashwrites an argon2id hash by default (see the argon2id entry), and a 60-character bcrypt hash starting with$2b$withalgorithm: 'bcrypt'.verifyreads bcrypt hashes written by thebcryptnpm package as well as argon2 hashes, whichever onehashwrites. No stored password is rehashed or migrated. - Cost configuration.
costapplies to bcrypt only: it accepts an integer from 4 to 31 and defaults to 10, and it needsalgorithm: 'bcrypt'. Invalid costs or non-string passwords throw an error naming the issue. - Failure handling.
verifyreturns false for empty or non-string inputs. Corrupt values that are not password hashes throw an error with status 500. - Passwords over 72 bytes (bcrypt only). Bun keeps all bytes, while the
bcryptpackage keeps only the first 72 bytes. argon2id has no such limit.- Reading old hashes.
verifyretries a bcrypt hash with the first 72 bytes of a longer password, so users whose hash the package wrote can still sign in. The retry is only for those legacy hashes: a hash thathashwrote, in either algorithm, is read on the first attempt. The price is that a hash of a password of exactly 72 bytes also accepts that password followed by anything, the way bcrypt always has. - Rolling back. A bcrypt hash that
hashwrites (withalgorithm: 'bcrypt') for a password longer than 72 bytes is read by Bun only. Thebcryptpackage cannot verify it, so going back to that package, or another service that reads the same column, locks those users out. Up to 72 bytes the two read each other's hashes.
- Reading old hashes.
- Documentation and examples. The docs and the
vertexample now useCredentialHelperinstead of thebcryptpackage.
Who is affected
- Existing callers. No action needed. Callers can replace
hash(password, await genSalt())withCredentialHelper.hash({ password, algorithm: 'bcrypt' })to keep writing bcrypt, or withCredentialHelper.hash({ password })for argon2id, andcompare(password, hash)withCredentialHelper.verify({ password, hash }).
Details
typescript
import { CredentialHelper } from '@venizia/ignis-helpers';
const stored = await CredentialHelper.hash({ password: 'hunter2' });
const ok = await CredentialHelper.verify({ password: 'hunter2', hash: stored });