mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: async hash calculation (#779)
This commit is contained in:
1 parent
e207cb4194
commit
e9a1ece808
5 files changed
+20
-14
No files matched your search
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user