mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-02-26 21:45:57 +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 bcrypt = require("bcryptjs");
|
||||||
|
|
||||||
|
|
||||||
const saltRounds = bcrypt.genSalt();
|
const saltRounds = bcrypt.genSaltSync();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash a password
|
* Hash a password
|
||||||
|
@ -20,13 +20,12 @@ exports.generate = function (password) {
|
||||||
* @returns {boolean} Does the password match the hash?
|
* @returns {boolean} Does the password match the hash?
|
||||||
*/
|
*/
|
||||||
exports.verify = function (password, hash) {
|
exports.verify = function (password, hash) {
|
||||||
if (isSHA1(hash)) {
|
let match;
|
||||||
return passwordHashOld.verify(password, hash);
|
match = isSHA1(hash) ? passwordHashOld.verify(password, hash) : bcrypt.compareSync(password, hash);
|
||||||
}
|
return match;
|
||||||
|
|
||||||
return bcrypt.compareSync(password, hash);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Is the hash a SHA1 hash
|
* Is the hash a SHA1 hash
|
||||||
* @param {string} hash
|
* @param {string} hash
|
||||||
|
@ -34,7 +33,7 @@ exports.verify = function (password, hash) {
|
||||||
*/
|
*/
|
||||||
function isSHA1(hash) {
|
function isSHA1(hash) {
|
||||||
return (typeof hash === "string" && hash.startsWith("sha1"));
|
return (typeof hash === "string" && hash.startsWith("sha1"));
|
||||||
}
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Does the hash need to be rehashed?
|
* Does the hash need to be rehashed?
|
||||||
|
|
Loading…
Add table
Reference in a new issue