Encrypt / decrypt passwords with node.js
I am working with bcrypt
nodejs module .
I am happy that it encrypts and compares passwords, but it cannot be decrypted.
I'm interested in:
- How do you encrypt / decrypt passwords with nodejs (which module or method are you using)?
- Is there a trick to decrypt passwords encoded with the module
bcrypt
?
Thank!
source to share
You don't decrypt passwords with bcrypt - it's a one-way algorithm. What you do is store a hash of the original (salt) password. Then you hash (salted) guesses. If the hashes match, then the assumption is correct.
For example, you can do this:
// "password"
var stored_hash = '$2a$10$vxliJ./aXotlnxS9HaJoXeeASt48.ddU7sHNOpXC/cLhgzJGdASCe'
bcrypt.compare(guess, stored_hash, function(err, res) {
});
Note that I did not do this with saline, so you will need to do this. node-bcrypt
salt the default hash.
source to share
A much better way to do this is to use this node module https://github.com/davidwood/node-password-hash , which can encrypt your password, and also let you encrypt the encrypted version with the actual one.
source to share