uptime-kuma/server/password-hash.js

24 lines
547 B
JavaScript
Raw Normal View History

2021-07-27 13:47:13 -04:00
const passwordHashOld = require("password-hash");
const bcrypt = require("bcryptjs");
2021-07-13 10:22:46 -04:00
const saltRounds = 10;
exports.generate = function (password) {
return bcrypt.hashSync(password, saltRounds);
2022-04-13 12:30:32 -04:00
};
2021-07-13 10:22:46 -04:00
exports.verify = function (password, hash) {
if (isSHA1(hash)) {
2022-04-13 12:30:32 -04:00
return passwordHashOld.verify(password, hash);
2021-07-13 10:22:46 -04:00
}
2021-07-27 13:47:13 -04:00
return bcrypt.compareSync(password, hash);
2022-04-13 12:30:32 -04:00
};
2021-07-13 10:22:46 -04:00
function isSHA1(hash) {
2022-04-13 12:30:32 -04:00
return (typeof hash === "string" && hash.startsWith("sha1"));
2021-07-13 10:22:46 -04:00
}
exports.needRehash = function (hash) {
return isSHA1(hash);
2022-04-13 12:30:32 -04:00
};