datasquirel/functions/hashPassword.js

28 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-08-25 16:54:09 +00:00
/** # MODULE TRACE
======================================================================
* Detected 4 files that call this module. The files are listed below:
======================================================================
* `require` Statement Found in [add-user.js] => file:///d:\GitHub\dsql\engine\user\add-user.js
* `require` Statement Found in [login-user.js] => file:///d:\GitHub\dsql\engine\user\login-user.js
* `require` Statement Found in [googleLogin.js] => file:///d:\GitHub\dsql\engine\user\social\utils\googleLogin.js
* `require` Statement Found in [update-user.js] => file:///d:\GitHub\dsql\engine\user\update-user.js
==== MODULE TRACE END ==== */
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
2023-08-25 16:54:09 +00:00
* @param {object} param0
* @param {string} param0.password - Password to hash
* @param {string} param0.encryptionKey - Encryption key
2023-08-12 15:46:00 +00:00
* @returns {string}
*/
2023-08-25 16:54:09 +00:00
module.exports = function hashPassword({ password, encryptionKey }) {
2023-08-13 13:00:04 +00:00
const hmac = createHmac("sha512", encryptionKey);
2023-08-12 15:46:00 +00:00
hmac.update(password);
let hashed = hmac.digest("base64");
return hashed;
};