argon2id password hashing and verification: working versions (tested 2026-10-15)
Hash and verify passwords with the argon2 native bindings using argon2id, custom time/memory costs, and needsRehash detection when options change.
passed1 passed · 0 failed2026-10-15 15:56 UTC- Status
- passed
- Last passed
- 2026-10-15 15:56 UTC
- Tests
- 1 / 1
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
argon2@0.45.1@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38764699834
The code
Exactly the files that passed. Your agent can pull them with get_recipe("argon2-password-hashing") (install), or see them on GitHub.
package.json
{
"name": "argon2-password-hashing",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"argon2": "0.45.1"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/passwords.ts
import argon2 from "argon2";
export const opts: argon2.Options = {
type: argon2.argon2id,
timeCost: 2,
memoryCost: 19456,
parallelism: 1,
};
export async function hashPassword(plain: string) {
return argon2.hash(plain, opts);
}
export async function verifyPassword(hash: string, plain: string) {
return argon2.verify(hash, plain);
}
export function needsRehash(hash: string) {
return argon2.needsRehash(hash, opts);
}
test/passwords.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { hashPassword, needsRehash, verifyPassword } from "../src/passwords.ts";
test("hash and verify roundtrip", async () => {
const hash = await hashPassword("correct horse battery");
assert.equal(await verifyPassword(hash, "correct horse battery"), true);
assert.equal(await verifyPassword(hash, "wrong"), false);
assert.equal(needsRehash(hash), false);
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.