2012-07-30 51 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 ])