spb/tools-spboucher-ai
Public
1import { hash, verify } from "@node-rs/argon2";2const OPTS = { algorithm: 2 /* Argon2id */, memoryCost: 65536, timeCost: 3, parallelism: 1, outputLen: 32 };3export const hashPassword = (pw: string) => hash(pw, OPTS);4export const verifyPassword = (h: string, pw: string) => verify(h, pw).catch(() => false);5export function passwordPolicy(pw: string): string | null {6 if (pw.length < 14) return "Password must be at least 14 characters.";7 if (/^\d+$/.test(pw)) return "Password cannot be only digits.";8 if (!/[a-z]/.test(pw) || !/[A-Z]/.test(pw) || !/[0-9]/.test(pw)) return "Use upper-case and lower-case letters and a digit.";9 return null;10}11