datasquirel/dist/package-shared/functions/dsql/hashPassword.js
Benjamin Toby 7e8bb37c09 Updates
2025-07-05 14:59:30 +01:00

16 lines
504 B
JavaScript

import { createHmac } from "crypto";
import grabKeys from "../../utils/grab-keys";
/**
* # Hash password Function
*/
export default function hashPassword({ password, encryptionKey, }) {
const { key } = grabKeys({ encryptionKey });
if (!(key === null || key === void 0 ? void 0 : 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;
}