dsql-admin/dsql-app/package-shared/functions/dsql/hashPassword.ts
Benjamin Toby 81cf010cb5 Updates
2025-01-14 16:27:08 +01:00

27 lines
582 B
TypeScript

import { createHmac } from "crypto";
import grabKeys from "../../utils/grab-keys";
type Param = {
password: string;
encryptionKey?: string;
};
/**
* # Hash password Function
*/
export default function hashPassword({
password,
encryptionKey,
}: Param): string {
const { key } = grabKeys({ encryptionKey });
if (!key?.match(/.{8,}/)) {
throw new Error("Encryption key is invalid");
}
const hmac = createHmac("sha512", key);
hmac.update(password);
let hashed = hmac.digest("base64");
return hashed;
}