脚本宝典收集整理的这篇文章主要介绍了php – 更改密码哈希类型的最有效方法(md5到sha1),脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
// The user is not authticated yet $auth = false; $updated = false; // From your Login form $user = $_POST['user']; $pass = $_POST['pass']; // Check If the username has update password $udated = false; // not update // I gues you always do this $password = $updated ? md5($pass) : sha1($pass); // Do the autentication // Slect from Database // Check the data // Set auth $auth = true; // Then chage the password if ($auth == true && !$updated) { $newpassword = sha1($pass); // Connect to DB // Update the Password // Set status to Updated in DB $udated = true; } // Better ApPRoch if ($auth == true && !$updated) { $newpassword = password_hash($password,PASSWORD_BCRYPT); // Connect to DB // Update the Password // Set Status to Updated in DB $updated = true; }
我使用password_hash有一个更好的方法,因为它使用BCRYPT这是一个更好的哈希算法. See more information on password_compat
以上是脚本宝典为你收集整理的php – 更改密码哈希类型的最有效方法(md5到sha1)全部内容,希望文章能够帮你解决php – 更改密码哈希类型的最有效方法(md5到sha1)所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。