mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-26 13:35:56 +00:00
reFactor verify function
This commit is contained in:
parent
1125752511
commit
0eb0c351ee
1 changed files with 6 additions and 7 deletions
|
@ -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?
|
||||
|
|
Loading…
Add table
Reference in a new issue