ai review

This commit is contained in:
lik
2026-09-01 21:49:41 +08:00
parent 70307d4eb8
commit 058e9135ae
9 changed files with 184 additions and 136 deletions
+9 -1
View File
@@ -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 };