This commit is contained in:
2026-04-14 18:05:32 +08:00
parent 68457c9fbd
commit 6378ab4994
40 changed files with 10488 additions and 113 deletions
+27
View File
@@ -0,0 +1,27 @@
import bcrypt from "bcryptjs";
import { createHash, randomBytes, randomUUID } from "node:crypto";
const BCRYPT_ROUNDS = 12;
export async function hashPassword(password: string): Promise<string> {
return bcrypt.hash(password, BCRYPT_ROUNDS);
}
export async function verifyPassword(
password: string,
passwordHash: string,
): Promise<boolean> {
return bcrypt.compare(password, passwordHash);
}
export function createOpaqueToken(size = 24): string {
return randomBytes(size).toString("base64url");
}
export function createStableId(): string {
return randomUUID();
}
export function sha256(input: string): string {
return createHash("sha256").update(input).digest("hex");
}