2010-07-17 119 views
0

我想製作一個鏈接到社交引擎數據庫的其他註冊頁面,但是當我MD5密碼並將其存儲在se_users表中時,用戶無法登錄,我相信社交引擎有另一種加密方法,有人可以給我一個函數來加密社交引擎的方式嗎?社交引擎密碼加密幫助

這是他們的功能,但我不知道如何實現它在我的腳本:

function user_password_crypt($user_password) 
{ 
global $setting; 

if(!$this->user_exists) 
{ 
    $method = $setting['setting_password_method']; 
    $this->user_salt = randomcode($setting['setting_password_code_length']); 
} 

else 
{ 
    $method = $this->user_info['user_password_method']; 
} 

// For new methods 
if($method>0) 
{ 
    if(!empty($this->user_salt)) 
    { 
    list($salt1, $salt2) = str_split($this->user_salt, ceil(strlen($this->user_salt)/2)); 
    $salty_password = $salt1.$user_password.$salt2; 
    } 
    else 
    { 
    $salty_password = $user_password; 
    } 
} 

$user_password_crypt = md5($salty_password); 

return $user_password_crypt; 
} 

感謝

+0

你的意思是哈希,而不是加密。 – igorw 2010-07-17 19:06:23

回答

1

他們追加和前面加上鹽密碼,他們通過MD5運行之前。

這是如何產生的鹽,看起來像一個隨機字符串,其長度在應用程序配置」

$this->user_salt = randomcode($setting['setting_password_code_length']); 

這裏指定他們劈成兩半一種鹽,和密碼之前把左側,而右側後」

list($salt1, $salt2) = str_split($this->user_salt, ceil(strlen($this->user_salt)/2)); 
$salty_password = $salt1.$user_password.$salt2; 

現在他們哈希密碼鹹魚:

$user_password_crypt = md5($salty_password); 

爲了正確解密,你必須做的是讀取該用戶的salt。

$username = $POST['username']; 
$password = $POST['password']; 
$user = get_user_from_database($username); 
list($salt1, $salt2) = str_split($user->salt, ceil(strlen($user->salt)/2)); 

$salted_password = md5($salt1.$password.$salt2); 

if($salted_password == $user->crypted_password) { 
    echo "Login successful"; 
} else { 
    echo "Invalid password"; 
} 

Here is the Wikipedia page關於密碼學中的鹽。

+0

嗨,感謝您的回答,但是如果生成的md5哈希將總是相同,如果它的一部分是隨機代碼? – 2010-07-17 19:14:47

+1

每次都不是隨機的。第一次創建用戶帳戶時,會生成一個隨機密碼並隨密碼一起保存。每次獲取用戶信息時,他的鹽都將與您第一次生成的字符串相同,而不是再次隨機。 – 2010-07-17 19:52:06

0

幾件事:

您是否正在存儲用戶密碼的MD5散列?根據你發佈的代碼,社交引擎正在抨擊哈希(一種防止彩虹表的方法)。

作爲一個方面,MD5哈希不是密碼安全的哈希密碼方式。此外,在登錄時對密碼進行哈希處理,並且傳輸哈希並不比以純文本傳遞密碼更安全。爲了安全地登錄,您需要通過HTTPS進行登錄(或通過加密密碼進行更正確的登錄)

3

社交引擎使用默認安全salt,用戶salt和用戶密碼的組合來加密密碼,所以您只需要結合這三個數據並轉換成md5即可。

$ enc_password = md5('default_decurity_salt','user_password','user_salt');

EX。 - MD5('6e3cf54ce0aa10bb69d69926e82b62b3be9022b9','123456'。'3486524');?

它的工作。

+2

它對我的作品感謝一噸 – 2013-01-09 05:05:48

2

你可以試試這個

MD5( 'default_salt', 'user_salt', 'USER_PASSWORD');