This commit is contained in:
Louis Lam 2025-06-17 18:26:33 +02:00 committed by GitHub
commit ee8ea87a48
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 8 additions and 8 deletions

View file

@ -26,7 +26,7 @@ exports.login = async function (username, password) {
// Upgrade the hash to bcrypt
if (passwordHash.needRehash(user.password)) {
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
passwordHash.generate(password),
await passwordHash.generate(password),
user.id,
]);
}

View file

@ -14,7 +14,7 @@ class User extends BeanModel {
*/
static async resetPassword(userID, newPassword) {
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
passwordHash.generate(newPassword),
await passwordHash.generate(newPassword),
userID
]);
}
@ -25,7 +25,7 @@ class User extends BeanModel {
* @returns {Promise<void>}
*/
async resetPassword(newPassword) {
const hashedPassword = passwordHash.generate(newPassword);
const hashedPassword = await passwordHash.generate(newPassword);
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
hashedPassword,

View file

@ -5,10 +5,10 @@ const saltRounds = 10;
/**
* Hash a password
* @param {string} password Password to hash
* @returns {string} Hash
* @returns {Promise<string>} Hash
*/
exports.generate = function (password) {
return bcrypt.hashSync(password, saltRounds);
return bcrypt.hash(password, saltRounds);
};
/**

View file

@ -674,7 +674,7 @@ let needSetup = false;
let user = R.dispense("user");
user.username = username;
user.password = passwordHash.generate(password);
user.password = await passwordHash.generate(password);
await R.store(user);
needSetup = false;

View file

@ -20,7 +20,7 @@ module.exports.apiKeySocketHandler = (socket) => {
checkLogin(socket);
let clearKey = nanoid(40);
let hashedKey = passwordHash.generate(clearKey);
let hashedKey = await passwordHash.generate(clearKey);
key["key"] = hashedKey;
let bean = await APIKey.save(key, socket.userID);

View file

@ -51,7 +51,7 @@ exports.initJWTSecret = async () => {
jwtSecretBean.key = "jwtSecret";
}
jwtSecretBean.value = passwordHash.generate(genSecret());
jwtSecretBean.value = await passwordHash.generate(genSecret());
await R.store(jwtSecretBean);
return jwtSecretBean;
};