Skip to content

Pwhash

Argon2id password hashing and key derivation from passwords - all operations are intentionally slow. Key derivation (hash): derives a fixed-length symmetric key from a password and a random salt. Password storage (hashStr/verifyStr): produces a self-contained encoded string with embedded salt. Use INTERACTIVE presets for login flows and SENSITIVE for long-lived key derivation.

Pwhash . hash ( password salt outputBytes opsLimit memLimit )  -> buffer

Derives a key of outputBytes bytes from password and a 16-byte salt using Argon2id. opsLimit and memLimit default to the interactive presets; increase to moderate or sensitive for stronger derivation.

Parameters

password: buffer
salt: buffer
outputBytes: number
opsLimit: number?
memLimit: number?

Returns

buffer
Pwhash . hashStr ( password opsLimit memLimit )  -> string

Hashes password for storage, returning a self-contained encoded string with embedded salt and parameters. opsLimit and memLimit default to the interactive presets; errors if hashing fails.

Parameters

password: buffer
opsLimit: number?
memLimit: number?

Returns

string
Pwhash . verifyStr ( hashString password )  -> boolean

Verifies that password matches the encoded hash produced by hashStr. Returns true if the password is correct, false otherwise - does not error on wrong passwords.

Parameters

hashString: string
password: buffer

Returns

boolean
Pwhash . needsRehash ( hashString opsLimit memLimit )  -> boolean

Returns true if the stored hash was produced with parameters weaker than opsLimit/memLimit. Use after a successful verifyStr to decide whether to upgrade the stored hash; errors if hashStr is invalid.

Parameters

hashString: string
opsLimit: number?
memLimit: number?

Returns

boolean