How to decrypt hash stored by bcrypt
To answer the original posters question.... to 'decrypt' the password, you have to do what a password cracker would do.
In other words, you'd run a program to read from a large list of potential passwords (a password dictionary) and you'd hash each one using bcrypt
and the salt and complexity from the password you're trying to decipher. If you're lucky you'll find a match, but if the password is a strong one then you likely won't find a match.
Bcrypt
has the added security characteristic of being a slow hash. If your password had been hashed with md5 (terrible choice) then you'd be able to check billions of passwords per second, but since it's hashed using bcrypt
you will be able to check far fewer per second.
The fact that bcrypt
is slow to hash and salted is what makes it a good choice for password storage even today. That being said I believe NIST
recommends the PBKDF2 for password hashing.
You're HASHING, not ENCRYPTING!
What's the difference?
The difference is that hashing is a one way function, where encryption is a two-way function.
So, how do you ascertain that the password is right?
Therefore, when a user submits a password, you don't decrypt your stored hash, instead you perform the same bcrypt
operation on the user input and compare the hashes. If they're identical, you accept the authentication.
Should you hash or encrypt passwords?
What you're doing now -- hashing the passwords -- is correct. If you were to simply encrypt passwords, a breach of security of your application could allow a malicious user to trivially learn all user passwords. If you hash (or better, salt and hash) passwords, the user needs to crack passwords (which is computationally expensive on bcrypt
) to gain that knowledge.
As your users probably use their passwords in more than one place, this will help to protect them.
You simply can't.
bcrypt
uses salting, of different rounds, I use 10 usually.
bcrypt.hash(req.body.password,10,function(error,response){ }
This 10 is salting random string into your password.