- 更新 .gitignore 文件,排除 Idea 项目配置 - 移除 vuepress 缓存目录 - 优化 app.js 中的错误处理和状态码导入- 调整 CORS 配置,移除未使用的 allowdHeaders - 更新 hashUtils.js 中的密码处理函数 - 优化 index.js 中的路由定义 - 更新 mongodbConfig.js 中的数据库连接逻辑 - 升级 express到 5.0.0- 更新 mongoose 到 8.7.1
22 lines
567 B
JavaScript
22 lines
567 B
JavaScript
const bcrypt = require('bcrypt')
|
|
|
|
async function hashPassword(password) {
|
|
try {
|
|
return await bcrypt.hash(password, 10)
|
|
} catch (err) {
|
|
console.error('Error hashing password:', err)
|
|
throw err // 重新抛出错误以便调用方处理
|
|
}
|
|
}
|
|
|
|
async function comparePassword(password, hashedPassword) {
|
|
try {
|
|
return await bcrypt.compare(password, hashedPassword)
|
|
} catch (err) {
|
|
console.error('Error comparing password:', err)
|
|
throw err // 重新抛出错误以便调用方处理
|
|
}
|
|
}
|
|
|
|
module.exports = { hashPassword, comparePassword }
|