关于stblog的一个问题
最近在研究stblog的代码遇到一个地方看不懂求高手们帮忙看下
首先看下面的代码:
这些代码来自一个类名叫Common的文件
public static function do_hash($string, $salt = NULL)
{
if(null === $salt)
{
$salt = substr(md5(uniqid(rand(), true)), 0, ST_SALT_LENGTH);
}
else
{
$salt = substr($salt, 0, ST_SALT_LENGTH);
}
return $salt . sha1($salt . $string);
}
public static function hash_Validate($source, $target)
{
return (self::do_hash($source, $target) == $target);
}
再看下面的代码:
这些代码是来自模型中的(上面所说的那个Common类文件一杯加载了)
public function validate_user($username, $password)
{
$data = FALSE;
$this->db->where('name', $username);
$query = $this->db->get(self::TBL_USERS);
if($query->num_rows() == 1)
{
$data = $query->row_array();
}
if(!empty($data))
{
$data = (Common::hash_Validate($password, $data['password'])) ? $data : FALSE;
}
$query->free_result();
return $data;
}
我主要看不懂的是这句
$data = (Common::hash_Validate($password, $data['password'])) ? $data : FALSE;
他是如何判断两个值是不是相等的啊??
其中 $data['password']是经过MD5和sha1加密过的不不可逆的
而$password是原始的字符串 ,再怎么加密 但是随机取的值总是不一样的啊??
很不好理解!
求高手帮忙………… 生成初始密码的时候 随机串保存在密码的(0, ST_SALT_LENGTH)区间
验证的时候 再把这段随机串截出来+ sha1(随机串 + 输入的密码)看是否和原来的一样
这样比单纯的md5加密更保密些吧。。。 弄明白了!谢谢诶楼上的!:handshake
页:
[1]