datasquirel/functions/hashPassword.js
2023-08-13 14:00:04 +01:00

17 lines
401 B
JavaScript

// @ts-check
const { createHmac } = require("crypto");
/**
* # Hash password Function
* @param {string} password
* @returns {string}
*/
module.exports = function hashPassword(password) {
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
const hmac = createHmac("sha512", encryptionKey);
hmac.update(password);
let hashed = hmac.digest("base64");
return hashed;
};