可以';t在数据库中插入特殊的哈希代码


can't insert special hash code into database

我想把散列后的密码保存在mysql数据库中,所以我在CodeIgniter中开发了以下方法。

private function hashing($password = '',$mail = '')
{
    $hashcode = md5($password, $mail);
    return sha1($hashcode,md5($hashcode.$mail));
}

插入:

$data = array('mail'=>$mail,'password'=>$password,'actived'=>1,'time'=>time());
$this->db->insert('users', $data);

其他字段插入正确,而不是密码。

它会产生类似的东西

åLmyÉZÔe+ú§3G"Çu"

它无法保存在mysql数据库中。问题出在哪里?

编辑数据库排序规则为utf8_unicode_ciedit我使用的是CodeIgniter,所以它不需要mysql_real_。。。

您可能打算这样做:

return sha1($hashcode . md5($hashcode.$mail));

取而代之的是:

return sha1($hashcode,md5($hashcode.$mail));

sha1()的第二个参数是一个布尔值,控制它是以原始格式还是字符串格式返回哈希(false=字符串,这是您想要插入的)。

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

您没有正确使用函数sha1,它的签名是

string sha1 ( string $str [, bool $raw_output = false ] )

因为md5函数的计算结果不是false(一些字符串),所以您将获得原始二进制输出。

顺便说一句,你在md5函数上犯了同样的错误,它的签名与sha1 相同

string md5 ( string $str [, bool $raw_output = false ] )