This commit is contained in:
Louis Lam 2025-06-15 19:53:07 +08:00
parent 609429bd7e
commit 4d666f8280
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 // Upgrade the hash to bcrypt
if (passwordHash.needRehash(user.password)) { if (passwordHash.needRehash(user.password)) {
await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [ await R.exec("UPDATE `user` SET password = ? WHERE id = ? ", [
passwordHash.generate(password), await passwordHash.generate(password),
user.id, user.id,
]); ]);
} }

View file

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

View file

@ -5,10 +5,10 @@ const saltRounds = 10;
/** /**
* Hash a password * Hash a password
* @param {string} password Password to hash * @param {string} password Password to hash
* @returns {string} Hash * @returns {Promise<string>} Hash
*/ */
exports.generate = function (password) { 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"); let user = R.dispense("user");
user.username = username; user.username = username;
user.password = passwordHash.generate(password); user.password = await passwordHash.generate(password);
await R.store(user); await R.store(user);
needSetup = false; needSetup = false;

View file

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

View file

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