想知道sha512是安全的,如果我把它与md5混合

时间:2013-05-29 09:02:22

标签: php

如果安全与否,我需要对我的代码进行一些检查

$pass = "jitubond";
$hashed_password =  md5($pass);
echo $hashed_password; // this is unsafe 100%
echo "<br>";
$hashed = hash("sha512", $pass); // style 1 
echo $hashed;
echo "<br>";
$hashed = hash("sha512", $hashed_password); // style 2 
echo $hashed;

你可以指导它可以用作密码吗?

谢谢大家=)

2 个答案:

答案 0 :(得分:1)

使用crypt()也更安全,你也可以定义轮数和盐(你应该使用盐),这也是PHP核心的一部分

http://php.net/manual/en/function.crypt.php

https://stackoverflow.com/a/10281510/753676

您也不能依赖hash(),因为它不是PHP核心的一部分 http://php.net/manual/en/faq.passwords.php

另外,PHPass是一个非常好的选择: https://security.stackexchange.com/questions/17111/php-crypt-or-phpass-for-storing-passwords

一些例子: http://net.tutsplus.com/tutorials/php/understanding-hash-functions-and-keeping-passwords-safe/

http://www.openwall.com/phpass/

Blowfish / bcrypt也被称为最安全的算法(但可能太昂贵了),您可以设置一些参数,如成本因素......

有些服务器还安装了mcrypt库的php,它支持更像TwoFish,TreeFish等http://www.php.net/manual/en/intro.mcrypt.php,但这可能太多了

答案 1 :(得分:-1)

sha512是一个非常好用的算法,首先使用md5是有点过分,只需使用sha512。

相关问题