php – 更改密码哈希类型的最有效方法(md5到sha1)
发布时间:2020-12-13 22:05:22 所属栏目:PHP教程 来源:网络整理
导读:我有一个系统使用MD5来散列用户的密码并将其存储到我的数据库中. 现在,我正在改用另一个使用SHA1(以及一个独特的系统SALT,而不是用户唯一的)来散列密码的系统. 如何通过PHP将用户旧的MD5密码设置为我的新SHA1密码? 解决方法 您无法将md5转换为sha,但实际上
我有一个系统使用MD5来散列用户的密码并将其存储到我的数据库中.
现在,我正在改用另一个使用SHA1(以及一个独特的系统SALT,而不是用户唯一的)来散列密码的系统. 如何通过PHP将用户旧的MD5密码设置为我的新SHA1密码? 解决方法
您无法将md5转换为sha,但实际上您的用户在登录时只使用密码,因此您可以稍微修改脚本以自动执行更新
// 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 – 如何在功能中使用参数CodeIgniter?
- php – 我无法使用imagecreatefrompng()打开此PNG文件
- php连接MSsql server的五种方法总结
- PHP tmux和屏幕没有正确的行为(没有启动,没有新的会话,没有
- PHP编程:php查找字符串出现次数的方法
- PHP下的Oracle客户端扩展(OCI8)安装教程
- [LeetCode]-008-String to Integer (atoi)
- 如何正确地将设置传递给CakePHP中的组件
- 使用PHP+MySql+Ajax+jQuery实现省市区三级联动功能示例
- php – 你可以在Guzzle POST Body中包含原始JSON吗?