嗨,所以我正在嘗試使用 sequelize 創(chuàng)建我的第一個(gè)登錄名,并且我正在努力處理散列和比較散列,它總是返回 false。由于我正在學(xué)習(xí),我認(rèn)為我在哈?;虮容^上做錯(cuò)了。我正在使用 SQL 數(shù)據(jù)庫這是我的登錄代碼,我正在使用快速會話和續(xù)集: 'processLogin': (req, res) => { db.User.findOne({ where: { email: req.body.email } }) .then(async user => { var eSession = req.session.userLogin let checkPass = await bcrypt.compare(req.body.password, user.password) console.log(checkPass); if(checkPass){ eSession = user; res.send("Success"); }else{ res.render('login', {errors: [{ msg: "Incorrect password" }]}); } if(user == undefined){ res.render('login', {errors: [{ msg: "User not found, please Register" }]});} }) }這里是我實(shí)際上在我的寄存器上散列密碼的地方: 'save': async (req, res) => { var a = [req.body.fullname, req.body.email, req.body.number, bcrypt.hashSync(req.body.password, 10), bcrypt.hashSync(req.body.repassword, 10)]; let errors = validationResult(req); if(errors.isEmpty()){ db.User.create({ full_name: a[0], email: a[1], phone_number: a[2], password: await bcrypt.hash(a[3], 10), confirm_password: await bcrypt.hash(a[4], 10) }) .then(users => { res.send("succes!!"); }) }else{ res.render('register', { errors: errors.errors }) } } }
Bcrypt.compareSync 總是返回 false
紫衣仙女
2022-10-21 09:36:51