2012-07-30 52 views
-1

我想在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 database.where是什么问题?

编辑数据库归类为utf8_unicode_ci 编辑我用笨,所以它不需要mysql_real _...

+0

向我们展示你所得到的错误。 – Daedalus 2012-07-30 23:13:29

+0

不显示任何错误,警告或通知。 – 2012-07-30 23:18:53

回答

2

你可能打算这样做:

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

相反其中:

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

012的第二个参数是一个布尔值,控制它是否以原始或字符串格式返回散列(false = string,这是您要插入的内容)。

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

2

你没有正确使用功能SHA1,它的签名是

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

因为MD5函数计算的东西,这不是假的(某些字符串),你会得到原始的二进制输出。

顺便问一下,你犯同样的错误与MD5函数,它具有相同的签名SHA1

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