datasquirel/dist/package-shared/functions/dsql/hashPassword.js
Benjamin Toby a3561da53d Updates
2025-01-10 20:35:05 +01:00

18 lines
662 B
JavaScript

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = hashPassword;
const crypto_1 = require("crypto");
/**
* # Hash password Function
*/
function hashPassword({ password, encryptionKey, }) {
const finalEncryptionKey = encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
if (!(finalEncryptionKey === null || finalEncryptionKey === void 0 ? void 0 : finalEncryptionKey.match(/.{8,}/))) {
throw new Error("Encryption key is invalid");
}
const hmac = (0, crypto_1.createHmac)("sha512", finalEncryptionKey);
hmac.update(password);
let hashed = hmac.digest("base64");
return hashed;
}