Best way to encode passwords in PHP

前端 未结 8 1693
死守一世寂寞
死守一世寂寞 2020-12-07 23:51

I currently use,
base64_encode() to encode a user\'s password, this works well because it allows me to simply use base64decode() to dec

8条回答
  •  情书的邮戳
    2020-12-08 00:08

    You should let a user RESET a password but never RETRIEVE their password. That is why you would want to use a one-way hash (SHA2) instead of a form of encryption that lets you decode it.

    Imagine if you left your email open. I could simply request to retrieve your password for some website, delete the email, and you would never know. On the other hand, if you required me to reset the password instead, the account password would change and the owner would obviously realize that something is wrong. (This is a dumb scenario but the concept is what's important)

    Hashes can be "reversed" by trying all possible combinations of words (or using rainbow tables) until a matching hash is produced. One way to avoid this is to append/prepend the provided password with a salt to make it a very long and unpredictable string. The salt should be a unique string of data unique to the individual's account.

    In PHP there is no SHA2 functon. SHA-2 is a family of hash algorithms, (SHA-256, SHA-384, SHA-512, etc...)

    hash('sha256', 'The quick brown fox jumped over the lazy dog.');
    

提交回复
热议问题