core: async hash calculation (#779)

This commit is contained in:
Yang Gao authored and GitHub committed 2024-04-09 08:13:50 +08:00
1 parent e207cb4194
commit e9a1ece808
5 files changed
+20 -14

No files matched your search

+5 -4
View File
@@ -141,10 +141,10 @@ export class User {
return false;
}
checkPassword(password: string) {
async checkPassword(password: string) {
const h = global.Hydro.module.hash[this.hashType];
if (!h) throw new Error('Unknown hash method');
const result = h(password, this._salt, this);
const result = await h(password, this._salt, this);
if (result !== true && result !== this._hash) {
throw new LoginError(this.uname);
}
@@ -290,7 +290,7 @@ class UserModel {
const salt = String.random();
const res = await coll.findOneAndUpdate(
{ _id: uid },
{ $set: { salt, hash: pwhash(password, salt), hashType: 'hydro' } },
{ $set: { salt, hash: await pwhash(password, salt), hashType: 'hydro' } },
{ returnDocument: 'after' },
);
deleteUserCache(res.value);
@@ -328,7 +328,8 @@ class UserModel {
mailLower: handleMailLower(mail),
uname,
unameLower: uname.trim().toLowerCase(),
hash: pwhash(password.toString(), salt),
// eslint-disable-next-line no-await-in-loop
hash: await pwhash(password.toString(), salt),
salt,
hashType: 'hydro',
regat: new Date(),