From 0eb0c351ee5501333496bfdc29d7a444da0a28dd Mon Sep 17 00:00:00 2001 From: kehiy Date: Mon, 15 May 2023 02:18:20 -0700 Subject: [PATCH] reFactor verify function --- server/password-hash.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/server/password-hash.js b/server/password-hash.js index 468b2a352..df723b218 100644 --- a/server/password-hash.js +++ b/server/password-hash.js @@ -2,7 +2,7 @@ const passwordHashOld = require("password-hash"); const bcrypt = require("bcryptjs"); -const saltRounds = bcrypt.genSalt(); +const saltRounds = bcrypt.genSaltSync(); /** * Hash a password @@ -20,13 +20,12 @@ exports.generate = function (password) { * @returns {boolean} Does the password match the hash? */ exports.verify = function (password, hash) { - if (isSHA1(hash)) { - return passwordHashOld.verify(password, hash); - } - - return bcrypt.compareSync(password, hash); + let match; + match = isSHA1(hash) ? passwordHashOld.verify(password, hash) : bcrypt.compareSync(password, hash); + return match; }; + /** * Is the hash a SHA1 hash * @param {string} hash @@ -34,7 +33,7 @@ exports.verify = function (password, hash) { */ function isSHA1(hash) { return (typeof hash === "string" && hash.startsWith("sha1")); -} +}; /** * Does the hash need to be rehashed?