php salt 我的每个用户的密码 sha512 - 我这样做对吗?

发布于 2024-11-17 07:15:06 字数 409 浏览 7 评论 0原文

我正在尝试为我的密码正确执行每个用户和站点范围的盐。这就是我得到的:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

夏了南城 2024-11-24 07:15:07

通常人们使用唯一的盐与密码连接,然后使用 hmac 方法添加站点范围的哈希密钥:

http://www.php.net/manual/en/function.hash-hmac.php

$password = hash_hmac('sha512', $password . $salt, $sitewide_key);

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

$password = hash_hmac('sha512', $password . $salt, $sitewide_key);
思念绕指尖 2024-11-24 07:15:07

这很好,只需从 "sha512" 中删除 "" :)

$pw = $_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);

不必使用 md5 sha512 本身就足够安全

This is fine just removed "" from "sha512" :)

$pw = $_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);

dont have to use md5 sha512 is secure enough it self

未央 2024-11-24 07:15:07

使用 crypt,它支持所有语言,并且您的密码哈希值也可以被其他程序使用:

$hash = crypt("secret", "$6$randomsalt$");

Use crypt, it's available in all languages and your password hashes will be useable by other programs as well:

$hash = crypt("secret", "$6$randomsalt$");
雨的味道风的声音 2024-11-24 07:15:07

根据这里的评论,我要做的就是:
将我的 $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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文