php salt 我的每个用户的密码 sha512 - 我这样做对吗?
我正在尝试为我的密码正确执行每个用户和站点范围的盐。这就是我得到的:
require('../../salt.php'); //this is above the web root and provides $salt variable
$pw = mysql_real_escape_string($_POST['pw']);
$per_user_salt = uniqid(mt_rand());
$site_salt = $salt //from salt.php that was required on first line
$combine = $pw . $per_user_salt . $site_salt;
$pw_to_put_in_db = hash("sha512", $combine);
这是正确的吗?谢谢
I'm trying to correctly do a per user and site wide salt for my passwords. Here's what I've got:
require('../../salt.php'); //this is above the web root and provides $salt variable
$pw = mysql_real_escape_string($_POST['pw']);
$per_user_salt = uniqid(mt_rand());
$site_salt = $salt //from salt.php that was required on first line
$combine = $pw . $per_user_salt . $site_salt;
$pw_to_put_in_db = hash("sha512", $combine);
Is this right? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
通常人们使用唯一的盐与密码连接,然后使用 hmac 方法添加站点范围的哈希密钥:
http://www.php.net/manual/en/function.hash-hmac.php
often people use a unique salt concatenated with the password, then use hmac method to add the sitewide hashing key:
http://www.php.net/manual/en/function.hash-hmac.php
这很好,只需从 "sha512" 中删除 "" :)
不必使用 md5 sha512 本身就足够安全
This is fine just removed "" from "sha512" :)
dont have to use md5 sha512 is secure enough it self
使用 crypt,它支持所有语言,并且您的密码哈希值也可以被其他程序使用:
Use crypt, it's available in all languages and your password hashes will be useable by other programs as well:
根据这里的评论,我要做的就是:
将我的
$combine
更改为每个用户唯一的但不存储在数据库中的内容。所以类似:$combine = $pw 。 md5($pw) 。 “小马是魔法”。 $site_salt 。 md5($pw);
等等等等...感谢您的帮助...所以 - 对于那些第一次尝试弄清楚如何执行此操作的人(像我一样)...它一切都与算法有关……创造一些晦涩、独特、难以理解的东西;因为如果有人想进入你的系统,他们就必须弄清楚这一点。感谢大家的精彩评论。
Based on comments here is what I'm going to do:
Change my
$combine
to something that is unique per user but not stored in db. So something like:$combine = $pw . md5($pw) . 'PoniesAreMagical' . $site_salt . md5($pw);
, etc etc etc... Thanks for the help...So - for those of you trying to figure out how to do this for the first time (like me)... its all about the algorithm... make something obscure, unique, difficult to figure out; because if someone wants to get into your system, they are going to have to figure this out. Thanks to all for awesome comments.