Tag: bcrypt

节点js – Bcrypt – 比较方法为正确的input密码返回false

我已经在这里经历了各种类似的问题,我试了一下,但仍然是,结果总是“错误的密码”。 我正在使用bcrypt for nodejs,而我的密码哈希存储在Postgresql数据库中。 hash和compare方法如下: generateHash : function(password, callBack){ bcrypt.genSalt(8, function(err, salt) { bcrypt.hash(password, salt, callBack); }); } validPassword : function(password, callBack){ bcrypt.compare(password, this.password, callBack); } 我在下面这段代码中使用了这些函数: //Generating hashing and DB storing User.generateHash(password, function(err, hash) { // if there is no user with that email // create the user var newUser = User.build({ email: email, […]

BCrypt哈希错误

这是我的散列密码的代码,并将已有的密码与已经发送到正文请求的密码进行比较: //hash password of document that use this schema bcrypt.hash(user.password, null, null, function (err, hashed) { if (err) { throw err; } else { user.password = hashed; //next api next(); } }) }); userSchema.methods.comparePassword = function (password) { //refer at userSchema var user = this; //return method of bcryot library that compare two string: original […]

Node.js Mongoose Promise迷路了

我有一个mongoDB的Node.js API。 有一个创build用户的路由,需要散列密码,为此我使用bcryptjs包。 路线如下所示: router.route('/user') .post(function(req, res) { if(req.body.password === req.body.passwordConfirm) { userManager.addUser(req.body) .then(function(response) { // waiting for the result of the mongoDB save res.send({data:response}); }); } else { res.send({err:'passwords do not match'}); } }) 和userManager.addUSer: this.addUser = function(userobject) { bcrypt.genSalt(10, function(err, salt) { // generate a salt if(err !== null) { console.log(err); } else […]

在没有Visual Studio的情况下安装bcrypt

我试图通过npm来安装bcrypt ,并且Failed at the bcrypt@0.7.8 install script.出现Failed at the bcrypt@0.7.8 install script. 错误。 我在Windows 8 x64,节点版本0.10.29。 看着bcrypt的依赖关系告诉我需要node-gyp ,这显然需要visual studio 2012和python。 真的? 我真的需要安装一个完整的IDE,我不打算使用这个节点模块吗? 是编译器node-gyp之后,还是VS的一些其他小组件可以安装,这将做的伎俩? 会喜欢有关如何使这个工作尽可能less的额外的任何build议。

如果函数不使用任何I / O,NodeJSasynchronous函数的目的是什么?

查看NodeJS bcrypt包( https://www.npmjs.com/package/bcrypt ),似乎有一对async / syncfunction: genSalt / genSaltSync 散列/ hashSync 比较/ compareSync 我了解asynchronous函数的用途,在函数具有I / O(如磁盘或networking访问)的情况下,以免阻塞事件循环。 但是,像上面这样的情况下,没有I / O的情况下,使用asynchronous版本有什么优势? select同步版本会损失什么? 我想这样做,因为它使更简单的代码,我看不出有任何缺点。 在https://stackoverflow.com/a/11606391/779159中,它表示“如果可能的话,您希望使用asynchronous版本,这样您就不会在密码散列期间占用您的节点处理”,但是您的代码不会无论如何,因为这些function使用的是CPU,而不是I / O,所以会受到阻碍吗?

使用与bcryptasynchronous的Sequelize

这可能是基于意见的。 但我想得到一些build议。 所以,我想要做的事情可以用这个线程中提到的方式来完成。 但是这个线程为我想要使用asynchronous做了一个好点。 这是我到目前为止,它的工作原理。 User.create({email: req.body.email, password: req.body.password}).catch(function(err){ console.log(err); }); User.beforeCreate(function(user) { const password = user.password; user.password = ''; bcrypt.genSalt(SALT_WORK_FACTOR, function(err, salt) { if(err) console.error(err); bcrypt.hash(user.password, salt, null, function(err, hash) { if(err) console.error(err); user.password = hash; user.save(); }); }); }); 由于我使用bcryptasynchronous,我将不得不坚持encryption的密码在另一个查询。 我的直觉告诉我可能有一个更好的方式使用bcryptasynchronous与sequ​​elize。 我的问题是,首选/更好的方法是什么? 或者我应该只是同步使用bcrypt?

您可以使用browserify来要求节点bcrypt客户端,然后将散列发送到服务器?

您可以使用browserify来要求节点bcrypt客户端,然后将散列发送到服务器? 这听起来真的很棒,或者它可以提供更高的安全性,然后通过SSL将明文传递给服务器? 如果我们通过websockets传递明文呢? 谢谢!

为什么node.bcrypt.js不能识别我的密码?

我正在考虑使用bcrypt( npm install bcrypt )为我的node.js应用程序散列密码。 我决定做两个小脚本作为概念的certificate,基本上遵循node.bcrypt.js的指示: createHash.js var bcrypt = require('bcrypt'), password = process.argv[2]; bcrypt.hash(password, 10, function(err, hash) { console.log(hash); }); checkPassword.js var bcrypt = require('bcrypt'), hash = process.argv[2], password = process.argv[3]; bcrypt.compare(password, hash, function(err, res) { console.log(res); }); 尝试一下看起来像这样: $ node createHash.js bacon $2a$10$Iy8XG2C5.OMysi2S9UK2fu3omruWE4nXnhSKRD2fmNnImEAqayJs2 $ node checkPassword.js $2a$10$Iy8XG2C5.OMysi2S9UK2fu3omruWE4nXnhSKRD2fmNnImEAqayJs2 bacon false 由于我使用相同的密码进行这两个调用( bacon ),我希望第二次调用返回true,而不是false。 任何人都可以解释为什么这不符合预期?

节点4.0和4.1的travis build中的node-gyp错误

当我运行Travis版本时,当它试图在节点版本4.0和4.1上运行node-gyp时,出现以下错误。 0.12和更低似乎没有这些问题,并build立良好。 我不确定这里是否有编译器问题? > bcrypt@0.8.5 install /home/travis/build/me/api/node_modules/bcrypt > node-gyp rebuild make: Entering directory `/home/travis/build/me/api/node_modules/bcrypt/build' CXX(target) Release/obj.target/bcrypt_lib/src/blowfish.o CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt.o CXX(target) Release/obj.target/bcrypt_lib/src/bcrypt_node.o In file included from /home/travis/.node-gyp/4.1.2/include/node/node.h:42:0, from ../node_modules/nan/nan.h:24, from ../src/bcrypt_node.cc:1: /home/travis/.node-gyp/4.1.2/include/node/v8.h:336:1: error: expected unqualified-id before 'using' /home/travis/.node-gyp/4.1.2/include/node/v8.h:469:1: error: expected unqualified-id before 'using' /home/travis/.node-gyp/4.1.2/include/node/v8.h:852:1: error: expected unqualified-id before 'using' In file included from ../node_modules/nan/nan.h:184:0, from ../src/bcrypt_node.cc:1: ../node_modules/nan/nan_maybe_43_inl.h:13:1: […]

升级现有的bcrypt散列轮数

我有一个数据库,对于我们的用例来说,大多数哈希值的循环次数太less。 我想升级这些到更高的轮次/迭代计数,希望与node.bcrypt.js库。 例: 我在我的数据库中有这样的东西 '$2a$05$Ss068.p/.i4IRzrYoLM/U.ETLpzwrBs2vVfViqgfC5bI4i3BGClZC' //From: bcrypt.hashSync("hello world", 5) 我希望它成为这样的东西: '$2a$10$6sZOFUEWdVMHoCsgF0k1..RhwoD7VmLlLc5.67/Qw81/XuSuNIOcO' //From: bcrypt.hashSync("hello world", 10) 有没有办法做到这一点? 我在想这个API可能是这样的: //Non-existing api; var hash = '$2a$05$Ss068.p/.i4IRzrYoLM/U.ETLpzwrBs2vVfViqgfC5bI4i3BGClZC'; const roundCount = 10 bcrypt.upgradeHashRoundCount(hash, roundCount) .then(function(upgradedHash){ console.log(upgradedHash) }) .catch(function(error){ console.error("Not a bcrypt hash, or has higher round-count than provided round count") }) 编辑澄清: 我想做一个批处理的工作,我得到所有的哈希,并进行每一个升级,没有原始密码可用。 由于bcrypt本质上是循环的,所以我认为理论上可以多走一些,然后存储回去。