2021-07-27 10:47:13 -07:00
|
|
|
const passwordHashOld = require("password-hash");
|
2021-08-31 04:56:44 -07:00
|
|
|
const bcrypt = require("bcryptjs");
|
2021-07-13 07:22:46 -07: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 10:47:13 -07:00
|
|
|
|
|
|
|
return bcrypt.compareSync(password, hash);
|
2021-07-13 07:22:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function isSHA1(hash) {
|
|
|
|
return (typeof hash === "string" && hash.startsWith("sha1"))
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.needRehash = function (hash) {
|
|
|
|
return isSHA1(hash);
|
|
|
|
}
|