- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用knex从数据库中选择特定的用户密码。这个哈希密码在这样的对象中返回给我:
[ anonymous {
password_hash:
'$2a$10$zRSFdNJsg8S3Xv1I73gjYuRu.Mw/9Dtujh0dTqrtc9DA12vUHuqbK' } ]
当我尝试使用
bcrypt.compareSync
比较输入的密码和数据库中存在的密码时,它给我一个错误,提示数据和哈希必须是字符串。我尝试使用
.toString()
方法和
JSON.stringify(password_hash)
。但是两者都没有帮助。我该如何工作?
knex('users').where({
email: req.body.loginEmail
}).select('password_hash')
.then(function(password_hash) {
//console.log("resp", password_hash)
console.log("JSON stringifies",JSON.stringify(password_hash))
console.log("req", req.body.loginPass)
console.log('hash', password_hash)
bcrypt.compareSync(req.body.loginPass, JSON.stringify(password_hash), function(err, doesMatch){
if (doesMatch){
console.log("Passwords Match")
req.session.email = rows[0].email;
var templateVars = {
emale: req.session.email
}
res.render('/dashboard', templateVars)
} else {
console.log("THIS IS THE ERROR", err);
res.send("I DONT KNOW YOU. SIGN UP FIRSt.")
}
})
})
我的整个错误:
Unhandled rejection Error: data and hash must be strings
at Object.compareSync (/vagrant/CaloBoxInc/node_modules/bcrypt/bcrypt.js:144:15)
at /vagrant/CaloBoxInc/server.js:159:14
at tryCatcher (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:512:31)
at Promise._settlePromise (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:569:18)
at Promise._settlePromise0 (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:614:10)
at Promise._settlePromises (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/promise.js:693:18)
at Async._drainQueue (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/async.js:133:16)
at Async._drainQueues (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/async.js:143:10)
at Immediate.Async.drainQueues (/vagrant/CaloBoxInc/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:570:20)
at tryOnImmediate (timers.js:550:5)
at processImmediate [as _immediateCallback] (timers.js:529:5)
最佳答案
可能是您的req.body.loginPass
不是字符串吗? JSON.stringify
始终返回undefined/string,如果参数未定义,则bcrypt返回不同的错误,因此参数不会成为问题。
尝试强制将req.body.loginPass
强制转换为这样的字符串:
bcrypt.compareSync(´´+ req.body.loginPass, ...
关于postgresql - bcrypt compareSync “Unhandled rejection Error: data and hash must be strings”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44063440/
密码散列的理想 bcrypt 工作因素是什么。 如果我使用因子 10,则在我的笔记本电脑上对密码进行哈希处理大约需要 0.1 秒。如果我们最终得到一个非常繁忙的网站,那么仅仅检查人们的密码就会变成大量
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
好吧,经过大量研究,我决定使用 bcrypt(请随意评论)在我的 PhoneGap 应用程序中散列和存储密码。 几天前,我偶然发现了 Bcrypt.net,它对我来说似乎“足够好”(再次,请随意发表评
我是 Ruby on Rails 的初学者,正在尝试向 http://ruby.railstutorial.org/ 学习我正在创建 example_app,但卡在了第 6 章。 我的Ruby版本:r
我是 Ruby on Rails 的初学者,正在努力学习 http://ruby.railstutorial.org/我正在创建 sample_app,但卡在了第 6 章。 我的 Ruby 版本:ru
我正在 Spring Hibernate MVC 中从事 Web 应用程序项目。我在 Spring security 中使用 Bcrypt 算法将编码密码存储在数据库中。 现在我想要解码该编码密码以停
我正在使用 sails js 框架来开发 Web 应用程序,并且我尝试安装 bcrypt 节点模块来进行密码哈希处理。但它显示以下错误 除了安装 python 或 VS c++ redistribut
我收到错误 Cannot find module 'bcrypt' in nodejs application 我尝试使用 npm install bcrypt 安装它,但仍然遇到问题 npm i b
我有一个 python 脚本,它将用户数据导入到 mongodb 中,该 mongodb 使用 bcrypt 来哈希用户的密码。 来自 mongodb 的数据也将在 Node.js Web 应用程序中
我想使用 Go 创建一个用户身份验证系统,但我无法登录帐户。我使用 bcrypt 来散列密码,然后将其保存到数据库 (MySQL)。当我想将它与插入的密码进行比较时,就会出现问题。我有这个错误:has
我尝试创建Minecraft 插件(这是我的第一个),但无法修复此错误: 因此,该插件编译良好,但是当代码必须执行此代码时: BCrypt.checkpw(mdp, result.getString(
嗨,我最近在我的项目中使用了 bcrypt npm 包的 bcrypt.genSalt 。使用 bcrypt.genSalt 的基本思想是为需要加密的密码生成 Salt。使用 bcrypt.genSa
这听起来像是一个奇怪的问题,我实际上不得不问这个感觉有点奇怪,但是在花了几个小时查看 MSDN 文档以了解添加的 bcrypt 例程之后在 Vista 中,我几乎得出结论,没有实际的 bcrypt 支
我想在我的 grails 项目中使用 bcrypt 散列算法,而不是它的 defaultSHA-256 消息摘要算法。要启用 bcrypt,您只需使用 grails install-plugin sp
关于bcrypt npm package ,我看到推荐使用异步版本。但是,我想真正了解两个版本在性能方面的差异(即事件循环、阻塞 I/O 等) 版本 1:异步 const hash = await b
我有一个问题,我可以在 node-bcrypt 和passport.js 中创建散列密码,但无法使用散列密码。 我使用 nodejs、express、mongodb、mongoose、passport
我目前正在尝试在我的 Spring Security 中使用 LDAP 实现 BCrypt。我的问题是 LDAP 是否支持此功能,如果支持,我该如何实现?查看下图,我没有将 BCrypt 视为 LDA
我创建了一个新的 Lumen 5.4 项目并尝试播种一些数据。在播种机中,我使用 bcrypt 来散列密码。但是当我运行 php artisan db:seed 时,我得到了这个错误: Call to
当我将 has_secure_password 添加到模型(继承自 ActiveRecord::Base)时,出现错误,指出“bcrypt-ruby 不是 bundle 的一部分”。 这里的日志是:
请帮我弄清楚为什么我无法在运行 ubuntu 14.04 的系统中安装 bcrypt 错误: somehostname@somehost:~$ pip install bcyrpt Collectin
我是一名优秀的程序员,十分优秀!