1. Hash a password
Bun.password.hash returns a salted argon2id hash by default — async because hashing is deliberately slow.
const hash = await Bun.password.hash(pw);Typorithm · medium
Step 1 of 8 · intro card
System & FFI
Bun.password.hash(pw) produces a salted argon2id hash by default (bcrypt is an option), and Bun.password.verify(pw, hash) checks an attempt. Both are async. Bun.hash() is a fast non-crypto hash for cache keys. Never store plaintext passwords.
await Bun.password.hash(pw) returns a salted, slow hash using argon2id by default; you can switch to bcrypt with { algorithm: "bcrypt", cost }. It is async because secure hashing is intentionally expensive.
await Bun.password.verify(pw, hash) compares a plaintext attempt to the stored hash and reads the algorithm and parameters out of the hash string itself, so you never re-specify them.
Bun.hash("cache-key") is a separate, fast, non-cryptographic hash meant for cache keys and deduplication — it is not salted or slow, so it must never be used for passwords.
Bun.password.hash defaults to salted argon2id; bcrypt is opt-in.
Bun.password.verify(pw, hash) checks an attempt, reading the algorithm from the hash.
Bun.hash is fast & non-crypto — for cache keys, never passwords.
const hash = await Bun.password.hash(pw);
const argon = await Bun.password.hash(pw, { algorithm: "argon2id" });
const bcrypt = await Bun.password.hash(pw, { algorithm: "bcrypt", cost: 12 });
const ok = await Bun.password.verify(pw, hash);
const id = Bun.hash("cache-key");Connect each part of the code to the concept before you type.
Bun.password.hash returns a salted argon2id hash by default — async because hashing is deliberately slow.
const hash = await Bun.password.hash(pw);argon2id is the default, modern memory-hard algorithm; you can name it explicitly.
{ algorithm: "argon2id" }Pass algorithm: "bcrypt" with a cost factor when you need bcrypt compatibility.
{ algorithm: "bcrypt", cost: 12 }Bun.password.verify checks a plaintext attempt against the stored hash and reads the algorithm from the hash itself.
const ok = await Bun.password.verify(pw, hash);Bun.hash is a fast, non-cryptographic hash for cache keys and dedup — never for passwords.
const id = Bun.hash("cache-key");Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.