ai review
This commit is contained in:
+9
-1
@@ -9,6 +9,14 @@ async function hashPassword(passwd) {
|
||||
return await bcrypt.hash(passwd, SALT_ROUNDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对 token 做哈希(用于 DB 存储,避免明文落库)
|
||||
*/
|
||||
async function hashToken(token) {
|
||||
const crypto = await import('crypto');
|
||||
return crypto.createHash('sha256').update(token).digest('hex');
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
* 支持 bcrypt 新密码和 MD5 旧密码(渐进式迁移)
|
||||
@@ -33,4 +41,4 @@ async function verifyPassword(passwd, storedHash, salt) {
|
||||
};
|
||||
}
|
||||
|
||||
export { hashPassword, verifyPassword };
|
||||
export { hashPassword, verifyPassword, hashToken };
|
||||
|
||||
Reference in New Issue
Block a user