lomavuokraus/lib/auth.ts
Tero Halla-aho 0bb709d9c5
Some checks failed
CI / checks (push) Has been cancelled
chore: fix audit alerts and formatting
2026-02-04 12:43:03 +02:00

20 lines
528 B
TypeScript

import bcrypt from "bcryptjs";
const DEFAULT_ROUNDS = 12;
export function getSaltRounds(): number {
const val = Number(process.env.BCRYPT_ROUNDS ?? DEFAULT_ROUNDS);
return Number.isInteger(val) && val > 8 ? val : DEFAULT_ROUNDS;
}
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, getSaltRounds());
}
export async function verifyPassword(
password: string,
hash: string,
): Promise<boolean> {
if (!hash) return false;
return bcrypt.compare(password, hash);
}