Best PHP hashing method for storing user passwords in a MySQL table?

前端 未结 6 1125
半阙折子戏
半阙折子戏 2021-02-05 22:57

I\'ve been reading Stack Overflow questions for about 15 minutes now and every single one seems to contradict the previous one I read. Bcrypt, SHA1, MD5, and so on. I currently

6条回答
  •  遇见更好的自我
    2021-02-05 23:02

    Use MD5, SHA1 or whatever encryption you want with a SALT.

    For this example, I'm just going to use MD5 for explanation sake.

    So user chooses a password, store that in $password for instance.

    Now create a salt that's specific to your application.

    $salt = 'my very own salt'; // or maybe make a random string for your salt
    

    Then do

    $more_difficult_password = md5($salt . $password);
    

    This way people can't use dictionary attacks by just googling your MD5 string if it ever got compromised somehow.

提交回复
热议问题