随着计算机硬件的快速发展,对于相对简单的密码采用md5加密可能很容易就破解出来了。所以这里采用hash的算法加密,长度要比md5的长一些.
/**
* 密码加密函数
* @param string $password 要加密的字符串
* @param string $random 随机码
* @return string
*/
function password_hash($password,$random = null){
if($random === null){
$random = substr(md5(uniqid(rand(),true)),0,9);
}else{
$random = substr($random,0,9);
}
return $random.sha1($password.$random);
}
//测试一下
echo password_hash("helloworld");
echo password_hash("helloworld",substr("加密过后的内容"),0,9);
本文介绍了一种使用SHA1和随机码的密码加密方法,通过增加密文长度提高密码的安全性。
1210

被折叠的 条评论
为什么被折叠?



