datasquirel/functions/hashPassword.js

17 lines
401 B
JavaScript
Raw Normal View History

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