Take the 2-minute tour ×
Information Security Stack Exchange is a question and answer site for Information security professionals. It's 100% free, no registration required.

In order to allow users to connect to my website, I encrypt their password using BCrypt since it is one of the slowest algorithms to decrypt (making a compromised database longer to be decrypted).

But I was wondering if that was enough -- or if combining it with a hashing algorithm like sha256/512 was better ?

In fact, that would mean :

clear password -> sha256 -> bcrypt -> stored in database.

Does adding the sha256 really increase the difficulty to decrypt these, or is the slowness of BCrypt sufficient?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

The short answer is, use bcrypt, not SHA256. Bcrypt already hashes the password, so if you are using bcrypt, there is no point to use both bcrypt+SHA256; it won't be any stronger. Bcrypt alone is sufficient.

There's a lot of advice on this site on exactly this topic. Search for "password hashing" and you'll find it.

See, e.g., How to securely hash passwords?, Which password hashing method should I use?, Most secure password hash algorithm(s)?, Do any security experts recommend bcrypt for password storage?.

You want to use a password hashing algorithm that is as slow as you can stand, to prevent offline dictionary attacks on people's passwords if your database is compromised.

Of course, that is not enough. There are a variety of steps you should take to make use of passwords as secure as possible. Here are a few:

  • Use site-wide SSL/TLS. Any attempt to visit your site through HTTP should immediately redirect to HTTPS.

  • Enable HSTS on your site. This tells browsers to only connect to you via HTTPS. Paypal uses it. It is supported in recent versions of Firefox and Chrome.

Search the site and you'll find lots more.

share|improve this answer
    
Thanks for the answer. I didn't know about HSTS and I will read about it. You answered my question when you said that bcrypt also hash the password and then it's useless to hash it again with sha. –  Cyril N. May 8 '12 at 19:03
    
Other than SSL to the client, I would still recommend salting the passwords. bycrypt(password.length() + password + salt). –  ewanm89 May 8 '12 at 22:41
    
@ewanm89, yes, a salt is a good idea -- but that is implicit in using bcrypt. One of the arguments to bcrypt is the salt. You basically can't use bcrypt without using a salt. –  D.W. May 8 '12 at 22:55
1  
The accepted answer in this thread disagrees; since BCrypt has a maximum length it can encode they recommend making the most of long passwords by hashing with SHA256 before feeding into BCrypt: security.stackexchange.com/questions/6623/… –  Chris Moschini Jun 18 '12 at 19:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.