bcrypt compareSync "Unhandled rejection Error: data and hash must be strings"

bcrypt.comparesync not working
bcrypt online
bcryptjs comparesync
bcrypt salt
bcrypt comparesync req body password
bcrypt.compare not working
bcryptjs vs bcrypt
cannot find module 'bcrypt'

I'm using knex to select a specific users password from my database. this hashed password is returned to me in an object like this:

[ anonymous { password_hash: '$2a$10$zRSFdNJsg8S3Xv1I73gjYuRu.Mw/9Dtujh0dTqrtc9DA12vUHuqbK' } ]

When I try using bcrypt.compareSync to compare the entered password and the password that exists in the database, it give me an error saying data and hash must be strings. I tried using the .toString() method and JSON.stringify(password_hash). But both dont help. How do I get this to work? Any help will be greatly appreciated. Thank you.

Here is my code:

    email: req.body.loginEmail
  .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.")

my entire error

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)

Could it be that your req.body.loginPass is not string? JSON.stringify always returns undefined / string and bcrypt returns different error if parameter is undefined so that paramater can't be the problem.

Try force casting req.body.loginPass to string like this:

bcrypt.compareSync(´´+ req.body.loginPass, ...

(just for debugging purposes... though you should already see from earlier console logs it it is not a string).

Node bCrypt.compareSync, The bcrypt library on NPM makes it really easy to hash and compare if(bcrypt. compareSync('somePassword', hash)) {; // Passwords match; }� Packs CommonJs/AMD modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jsx, es7, css, less, and your custom stuff.

This error arises if one or more arguments passed to bcrypt.compareSync function are either undefined or null.

bcrypt-nodejs.compareSync JavaScript and Node.js code examples , error: Error: data and hash arguments required. Line in question: if (!bcrypt. compareSync(password, user.password)) { return done(null, false); }. bcrypt-nodejs. Warning : A change was made in v0.0.3 to allow encoding of UTF-8 encoded strings. This causes strings encoded in v0.0.2 or earlier to not work in v0.0.3 anymore. Native JS implementation of BCrypt for Node. Has the same functionality as node.bcrypt.js expect for a few tiny differences. Mainly, it doesn't let you set the seed

The solution to this problem is by changing the datatype of the password field in your Database to char(150) to avoid truncation. I hope that helps.

bcryptjs.compareSync JavaScript and Node.js code examples , async and sync ways. Bcrypt is way faster than bcryptjs, although users prefer … compareSync(myPlaintextPassword, hashSync);console. BCrypt was created for OpenBSD. When they had a bug in their library, they decided to bump the version number. Algorithm. The bcrypt algorithm is the result of encrypting the text "OrpheanBeholderScryDoubt" 64 times using Blowfish. In bcrypt the usual Blowfish key setup function is replaced with an expensive key setup (EksBlowfishSetup) function:

Hashing Passwords with Node.js and Bcrypt � A Beautiful Site, bcrypt.compareSync(stringKey, hash);. Its returning me false in every case. Any ideas what is going on? Thnx� Bcrypt is 3.1 times faster than bcryptjs in generating hash passwords and 1.3 times faster in comparing function. 3.Conclusion. Bcrypt is way faster than bcryptjs, although users prefer bcryptjs

[SOLVED] bcrypt.compareSync() not understanding hash , Node bCrypt.compareSync does not work. I am creating a user login. I am able to have the user sign up and when the user sings up his password is encrypted� bcrypt.compareSync(req.body.password, hash); If requested password match with the hash password then compareSync will return true. Asynchronous Usase.

Bcrypt vs BcryptJS Benchmark with Node.js, Tagged with bcrypt, security, node, javascript. compareSync(oldPassword, currentPasswordHash)) { console.log("The Current Password is� The bcrypt library on NPM makes it really easy to hash and compare passwords in Node. If you're coming from a PHP background, these are roughly equivalent to password_hash() and password_verify(). Bcrypt is the de facto way to hash and store passwords. For a brief explanation of why we use one-way

  • Could you add complete testcase for example with runkit, which reproduces your problem?
  • pls, update your question with full code.
  • I tried it... still getting the same error. Instead of rendering, I even tried redirecting, but thats of no help either...