- 更新导入路径,使用 .js 后缀 -修正用户模型中的密码加密和验证逻辑 - 优化用户路由和控制器 - 重构用户服务和仓库,使用原生 mongoose 方法- 更新错误处理和日志记录
21 lines
472 B
JavaScript
21 lines
472 B
JavaScript
import bcrypt from 'bcrypt'
|
|
|
|
/**
|
|
* 加密密码
|
|
* @param {string} password 密码
|
|
* @returns password 加密后的密码
|
|
*/
|
|
export async function hashPassword(password) {
|
|
return bcrypt.hash(password, 10)
|
|
}
|
|
|
|
/**
|
|
* 比较密码
|
|
* @param {string} password 密码
|
|
* @param {string} hashedPassword 哈希密码
|
|
* @returns {boolean} 是否匹配
|
|
*/
|
|
export async function comparePassword(password, hashedPassword) {
|
|
return bcrypt.compare(password, hashedPassword)
|
|
}
|