1
0
mirror of https://github.com/louislam/uptime-kuma.git synced 2024-12-10 10:10:14 +02:00
uptime-kuma/server/password-hash.js

24 lines
542 B
JavaScript
Raw Normal View History

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