1

I am using nodejs library scrypt to hash my passwords.

scrypt.hash(new Buffer(data.password), scryptParameters, function(err, res) {
  console.log(res);
  //scrypt.verify(res, "incorrect password");
});

which works perfectly. But, the problem is when I uncomment the line to verify the hash (I have put it in the same function (and syncronously) just for the sake of simplicity)

The script just crashes without any errors! this is what I get in the console

/Users/foo/Documents/nodejs/wow/models/user.js:44
    scrypt.verify(res, "incorrect password");
           ^
[object Object]
31 Jul 10:26:52 - [nodemon] app crashed - waiting for file changes before starting...

also it seems like it is trying to put some sort of object, that is [object Object]. I am not console.log'ing it, as I get nothing in the console before uncommenting that line.

Anyone had the same problem? Thanks in advance.

2
  • node version? scrypt version? scryptParameters? Commented Jul 31, 2014 at 1:49
  • "scrypt": "~3.0.1". node v0.10.18 . scryptParameters {N:1,r:1,p:1} all encodings are in buffer. Commented Jul 31, 2014 at 1:51

1 Answer 1

1

The problem is that you're using the wrong key encoding for scrypt.verify(). By default it expects a Buffer, but you're supplying a string. Either change the "incorrect password" to be a Buffer or do this:

scrypt.hash(new Buffer(data.password), scryptParameters, function(err, res) {
  scrypt.verify.config.keyEncoding = "utf8";
  scrypt.verify(res, "incorrect password");
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.