This commit is contained in:
Benjamin Toby
2024-12-08 09:58:57 +01:00
parent 8a8257d17e
commit 7bd4b2fe65
76 changed files with 1783 additions and 1106 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
declare function _exports({ password, encryptionKey }: {
password: string;
encryptionKey: string;
encryptionKey?: string;
}): string;
export = _exports;
+9 -12
View File
@@ -1,13 +1,3 @@
/** # 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 ==== */
// @ts-check
const { createHmac } = require("crypto");
@@ -16,11 +6,18 @@ const { createHmac } = require("crypto");
* # Hash password Function
* @param {object} param0
* @param {string} param0.password - Password to hash
* @param {string} param0.encryptionKey - Encryption key
* @param {string} [param0.encryptionKey] - Encryption key
* @returns {string}
*/
module.exports = function hashPassword({ password, encryptionKey }) {
const hmac = createHmac("sha512", encryptionKey);
const finalEncryptionKey =
encryptionKey || process.env.DSQL_ENCRYPTION_PASSWORD;
if (!finalEncryptionKey?.match(/.{8,}/)) {
throw new Error("Encryption key is invalid");
}
const hmac = createHmac("sha512", finalEncryptionKey);
hmac.update(password);
let hashed = hmac.digest("base64");
return hashed;