loginflow
v1.0.0
Published
Password auth helper: scrypt hashing/verification + brute-force lockout tracker. Zero dependencies.
Maintainers
Readme
loginflow
Password authentication + login-flow helper for Node.js. Zero dependencies. Hash and verify passwords with Node's scrypt, and guard against brute-force login attempts with an in-memory failed-attempt lockout tracker.
Pricing
Free. MIT-licensed, open source. No fees, no tiers.
Install
npm install loginflowUsage
const { hashPassword, verifyPassword, createLoginTracker } = require("loginflow");
// --- Password hashing & verification ---
const hash = hashPassword("correct horse battery staple");
// => "scrypt$16384$8$1$<salt>$<key>"
verifyPassword("correct horse battery staple", hash); // true
verifyPassword("wrong", hash); // false
// --- Brute-force lockout tracking ---
const tracker = createLoginTracker({ maxAttempts: 3, lockoutMs: 60_000 });
function attemptLogin(username, password) {
if (tracker.isLocked(username)) {
return { ok: false, locked: true, retryAfter: tracker.retryAfter(username) };
}
const ok = verifyPassword(password, findUserHash(username));
if (ok) {
tracker.success(username);
return { ok: true };
}
const state = tracker.failed(username);
return { ok: false, locked: state.locked, remaining: state.failures };
}API
hashPassword(password, { N, r, p, keylen })→ scrypt hash stringverifyPassword(password, storedHash)→ boolean (timing-safe)createLoginTracker({ maxAttempts, lockoutMs })→ trackerfailed(username)·success(username)·isLocked(username)·stateOf(username)·retryAfter(username)
License
MIT © shinnjr
