1. sha1 --计算字符串的 sha1 散列值
返回值
返回 sha1 散列值字符串。默认返回值是一个 40 字符长度的十六进制数字。
$str = 'apple';
if (sha1($str) === 'd0be2dc421be4fcd0172e5afceea3970e2f3d940') {
echo "Would you like a green or red apple?";
}
?>
2.md5—计算字符串的 MD5 散列值
返回值
以 32 字符十六进制数字形式返回散列值。
加盐:
function hash($a) {
$salt=”Random_KUGBJVY”; //定义一个salt值,程序员规定下来的随机字符串
$b=$a.$salt; //把密码和salt连接
$b=md5($b); //执行MD5散列
return $b; //返回散列
}
?>
sha1(md5($pass))
The suggestion to double-hash your password is not a good idea. You are much much better off adding a variable salt to passwords before hashing (such as the username or other field that is dissimilar for every account).
Double hashing is *worse* security than a regular