← All packages

@lacspace/lock

v1.0.5Security Kit0 deps

Account lockout & brute-force protection (server lock) — N-strikes, exponential backoff, self-resetting window, pluggable store. Zero-dependency, isomorphic.

npm i @lacspace/lock

Usage

lock.ts
import { lockout } from "@lacspace/lock";

const guard = lockout({ maxAttempts: 5, baseDelayMs: 60_000, maxDelayMs: 3_600_000 });

// before checking the password
const status = await guard.check(email);
if (status.locked) throw new Error(`Too many attempts. Try again in ${Math.ceil(status.retryAfterMs / 1000)}s`);

if (await verifyPassword(input, stored)) {
  await guard.reset(email);          // success — clear strikes
} else {
  const s = await guard.record(email); // failure — may lock
  throw new Error(s.locked ? "Account temporarily locked." : `${s.remaining} attempts left`);
}

Exports 3

LockoutMemoryLockStorelockout

Keywords

account-lockoutbrute-forcelogin-securitylockoutbackoffauth

More in Security Kit