Is time() a good salt?

后端 未结 9 1038
灰色年华
灰色年华 2020-12-02 05:40

I\'m looking at some code that I have not written myself. The code tries to hash a password with SHA512 and uses just time() as the salt. Is time()

9条回答
  •  爱一瞬间的悲伤
    2020-12-02 06:20

    Yes.
    It seems that a unix timestamp, stored in the user database as a "Member since" field going to be decent salt.

    However, salt question is most negligible one. There are much more important things you have to pay attention to:

    1. Most likely not a password nor salt or hashing algorithm going to be weakest part of your site. Some lame file injection or XSS or CSRF surely is. So, don't make a too big deal of it.
      Speaking of a true random string of 32 char long in the typical web-application is like speaking about 32-inch armored door in the wooden barn.

    2. Speaking of passwords, most ever important thing is password complexity. With weak password no salt nor hashing algorithm, even super-ingenious-incredible-hard one, could help. It's a pain to ask users to use complex password, but without it everything else becomes a piece of crap.
      So, your first concern should be password complexity. 12-16 characters of different case, including numbers and punctuation is a requirement.

    3. As for the salt, I see no benefit in using time, as you have to store it along with other user data. Better use a email - it's random enough and you have it already anyway. Don't forget to rehash a password if user changes their email. it seems that unix timstamp going to be a decent salt, no need to use email or anything else.

    Update
    As I can see, many people still unable to get the point.
    Like that guy from the comments, saying

    Many users use weak passwords (we should educate them, or at least keep trying), but that is no excuse; they still deserve good security

    They deserve, no doubt. But with weak password the mission. is. impossible.

    If your password is weak, then no salt will protect it.

    While salt is not that important to spend a 10-kilobyte text on the topic.

提交回复
热议问题