node-rs icon indicating copy to clipboard operation
node-rs copied to clipboard

How to pass `salt` generated via `genSalt` to bcrypt `hash()`?

Open dlongley opened this issue 3 years ago • 3 comments

There are bcrypt functions exposed for generating salts (genSalt/genSaltSync), but it doesn't seem possible to pass their returned values to hash() as an alternative to the rounds parameter. I didn't see anything in the documentation or examples -- and it didn't seem possible in the source nor did there seem to be any tests that combined the functions. Did I just miss how to do it? Or is this an oversight / just not supported yet?

dlongley avatar Apr 13 '22 22:04 dlongley

I checked the documentation and can't migrate because of this. Is this issue still valid?

ayZagen avatar Apr 22 '24 11:04 ayZagen

The salt is automatically generated and included in the final hash when the hash function is called. Is there a specific reason why you need to provide the salt manually?

https://github.com/napi-rs/node-rs/blob/59fddf62f9c0eaa21443a540cbd6d900d0eb2672/packages/bcrypt/src/lib.rs#L80

marcocondrache avatar Oct 06 '24 08:10 marcocondrache

However, looking at the bindings, it seems the hash functions can also handle externally provided salts.

https://github.com/napi-rs/node-rs/blob/main/packages/bcrypt/binding.d.ts

marcocondrache avatar Oct 06 '24 08:10 marcocondrache