views:

101

answers:

5

I need to store hashes of passwords on disk. I am not entirely sure which hash function to use (they all seem somewhat troubled at the moment), but I am leaning towards SHA-256.

My plan is to take the user's password and combine it with their user ID, a random user-specific salt, and a universal site-wide salt. Should I concatenate these values together and then hash the single resulting string, or should I hash each separately, concatenate the hashes, and then hash that? Also, does the order (password, user id, user salt, site salt) matter? Can I rearrange them however I like, or is it a bad idea to have something that doesn't change (site salt) or something completely predictable (user id/user salt) first?

Thanks.

A: 

Previous SO questions about this:

http://stackoverflow.com/questions/1246463/password-handling-best-practices/1246560#1246560

http://stackoverflow.com/questions/116684/what-algorithm-should-i-use-to-hash-passwords-into-my-database

But to provide brief answers to your specific questions:

  • SHA-256 is a viable option.
  • You can hash the single string.
  • Order doesn't matter.
  • You don't need two salts. Just a user-specific salt is fine, the site-wide one is unnecessary and doesn't actually contribute anything.
Amber
Grr - beat me by 18 Seconds. Sorry for the duplication :D
apocalypse9
No worries - that's somewhat the nature of StackOverflow. :)
Amber
+2  A: 

SHA-256 seems to be one of the better options available right now.

Concatenating everything should be fine and order isn't all that important. Just make sure that you are using a significantly long salt value.

This post has some good recommendations- http://stackoverflow.com/questions/116684/what-algorithm-should-i-use-to-hash-passwords-into-my-database

apocalypse9
+1  A: 

Why not bcrypt? Password hashing should be very slow, but SHA* is designed to be very fast. bcrypt is specifically designed for password hashing.

jrockway
A: 

Go all the way, SHA-512 FTW!

A: 

Never hash hashes!!

Chris Kaminski
Just curious, why not?
Moshe
Good question - I have no idea what I thinking at the time... Perhaps simply because if a hash is predictable, so is a hash of a hash - you still want to salt it.
Chris Kaminski