lomavuokraus/lib/auth.ts
2025-11-24 17:15:20 +02:00

17 lines
521 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);
}