Going from unsalted to salted MD5 passwords

后端 未结 12 1033
臣服心动
臣服心动 2021-02-07 02:56

I have a LAMP (PHP) website which is becoming popular.

I played it safe by storing the user passwords as md5 hashes.

But I now see that\'s not secure; I should h

12条回答
  •  眼角桃花
    2021-02-07 03:55

    sadly, your only way is to tell your users to renew their passwords.

    you could also generate random passwords, but that is the same hassle.

    edit

    you could just double encode your stored passwords. so your new salted hashing algorithm would be:

    md5(md5($new_password).$salt).':'.$salt
    

    to update your old passwords use

    md5($old_password.$salt).':'.$salt
    

    to check if a provided password is correct simply use

    list($stored_password, $salt) = explode(':', $salted_password);
    if(md5(md5($provided_password).$salt) == $stored_password) {
      // you are now logged in
    }
    

提交回复
热议问题