This commit is contained in:
jason
2026-04-20 15:49:01 -05:00
parent 381a31d607
commit b98837a72c
46 changed files with 8883 additions and 37 deletions
+29
View File
@@ -0,0 +1,29 @@
import bcrypt from "bcryptjs";
const ADMIN_ROUNDS = 12;
const PIN_ROUNDS = 12;
export async function hashPassword(password: string): Promise<string> {
if (!password || password.length < 8) {
throw new Error("Password must be at least 8 characters");
}
return bcrypt.hash(password, ADMIN_ROUNDS);
}
export async function verifyPassword(password: string, hash: string): Promise<boolean> {
return bcrypt.compare(password, hash);
}
export function isValidPin(pin: string): boolean {
return /^\d{4}$/.test(pin);
}
export async function hashPin(pin: string): Promise<string> {
if (!isValidPin(pin)) throw new Error("PIN must be exactly 4 digits");
return bcrypt.hash(pin, PIN_ROUNDS);
}
export async function verifyPin(pin: string, hash: string): Promise<boolean> {
if (!isValidPin(pin)) return false;
return bcrypt.compare(pin, hash);
}