32 lines
716 B
TypeScript
32 lines
716 B
TypeScript
import bcrypt from "bcryptjs";
|
|
import { logger } from "../monitoring/logger.js";
|
|
|
|
const SALT_ROUNDS = 10;
|
|
|
|
/**
|
|
* Hasht ein Passwort
|
|
*/
|
|
export async function hashPassword(password: string): Promise<string> {
|
|
try {
|
|
return await bcrypt.hash(password, SALT_ROUNDS);
|
|
} catch (error) {
|
|
logger.error("Password hashing failed", { error });
|
|
throw new Error("Fehler beim Hashen des Passworts");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Vergleicht ein Passwort mit einem Hash
|
|
*/
|
|
export async function comparePassword(
|
|
password: string,
|
|
hash: string
|
|
): Promise<boolean> {
|
|
try {
|
|
return await bcrypt.compare(password, hash);
|
|
} catch (error) {
|
|
logger.error("Password comparison failed", { error });
|
|
return false;
|
|
}
|
|
}
|