Argon2 Password Hash With Params
Hash passwords with Argon2id using explicit memory time and parallelism parameters and verify with constant-time comparison.
Code
import{argon2id,verify}from'argon2';export async function hashPassword(pw){return argon2id(pw,{memoryCost:19456,timeCost:2,parallelism:1,hashLength:32});}export async function verifyPassword(hash,pw){try{return await verify(hash,pw);}catch{return false;}}export function needsRehash(hash,{memoryCost=19456,timeCost=2}={}){return!hash.includes('m='+memoryCost)||!hash.includes('t='+timeCost);}From first line to last
Argon2 Password Hash With Params keeps everything in the functions hashPassword, verifyPassword and needsRehash.
Asynchronous boundaries use await, so failures surface as rejected promises at the call site instead of being swallowed. Everything borrowed from argon2 is visible in one line: argon2id, verify.
What to watch for
- Dependency check:
argon2— not built-in, must be present in the project.
Applying it
The main signature reads export async function hashPassword(pw)
hashPassword is the public entry point; everything else in the file exists to support it.
Interactive Tools for This Topic
Argon2id Hash InfoEstimate Argon2id password-hash latency and memory usage, and check your parameters against OWASP 2024 minimum and recommended settings.Basic & Bearer Auth Header ToolEncode and decode HTTP Authorization Basic and Bearer headers locally with UTF-8 Base64 validation and automatic JWT claim and expiry inspection.JWT Expiry CalculatorDecode a JWT payload and convert its exp, iat, and nbf claims into UTC ISO timestamps, with an expired-or-valid verdict.bcrypt Cost EstimatorEstimate bcrypt cost factor latency and brute-force resistance, and get a recommended cost for your target hash time and attacker throughput.
FAQ
- What does this need from the package registry?
- These are real dependencies: `argon2`. Without it the snippet will not load.
Report a problem with this exampleOpens a pre-filled issue on GitHub.