Initial commit: Kalendartool (Next.js, Prisma, Docker)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
21
lib/auth/password.ts
Normal file
21
lib/auth/password.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Passwort-Hashing mit bcrypt (plan.md Abschnitt 11:
|
||||
* "Passwoerter niemals selbst verschluesseln oder im Klartext speichern").
|
||||
*/
|
||||
import bcrypt from 'bcryptjs';
|
||||
|
||||
/** Kostenfaktor: 12 Runden sind aktueller Standard (ca. 200-300 ms). */
|
||||
const BCRYPT_ROUNDS = 12;
|
||||
|
||||
/** Hasht ein Klartext-Passwort fuer die Speicherung in der Datenbank. */
|
||||
export async function hashPassword(plainPassword: string): Promise<string> {
|
||||
return bcrypt.hash(plainPassword, BCRYPT_ROUNDS);
|
||||
}
|
||||
|
||||
/** Prueft ein Klartext-Passwort gegen den gespeicherten Hash. */
|
||||
export async function verifyPassword(
|
||||
plainPassword: string,
|
||||
passwordHash: string,
|
||||
): Promise<boolean> {
|
||||
return bcrypt.compare(plainPassword, passwordHash);
|
||||
}
|
||||
Reference in New Issue
Block a user