dcodeIO / bcrypt.js

Optimized bcrypt in plain JavaScript with zero dependencies.
Other
3.47k stars 264 forks source link

hashSync(process.env.password, salt) - throwing an error #74

Closed sampjr closed 6 years ago

sampjr commented 6 years ago

I have a .env.password variable, that I pass under JSON.stringify(password.env.password) to fit the hashSync arguments, but I end up with this error:

throw Error("Illegal arguments: "+(typeof s)+', '+(typeof salt));

My code looks like this: var hashed_pw = JSON.stringify(password.env.password); console.log(hashed_pw); //this just add the "" to the beginning and end of my pw var salt = bcrypt.genSalt(10); var hash = bcrypt.hashSync(hashed_pw, salt);

I don't know what to do.

Ruffio commented 6 years ago

You are mixing things up. Either use sync or async methods, you can't mix them.

You are using the async method of salt generation (genSalt) but the sync method of hashing (hashSync). So when your hashSync is executing the salt hasn't been generated and therefore salt is null.

Here is for sync method (as you can read in th readme... ;-)): var salt = bcrypt.genSaltSync(10); var hash = bcrypt.hashSync("B4c0/\/", salt);

sampjr commented 6 years ago

Oh I see, thank you!