0

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.

4 Answers4

2

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- What algorithm should I use to hash passwords into my database?

Community
  • 1
  • 1
Kelly Robins
  • 7,168
  • 6
  • 43
  • 66
1

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
  • 42,082
  • 9
  • 61
  • 86
0

Previous SO questions about this:

Password handling best practices?

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.
Community
  • 1
  • 1
Amber
  • 507,862
  • 82
  • 626
  • 550
0

Never hash hashes!!

Chris K
  • 11,996
  • 7
  • 37
  • 65
  • 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 K Oct 22 '10 at 14:38
  • You shouldn't re-hash a raw hash (without a salt) because it will expose – jmkeyes Jan 10 '13 at 10:28