[英]using php to create a joomla user password?
我正在嘗試為Joomla創建一個自定義注冊組件,我想知道是否有人知道如何為joomla創建正確的密碼加密? Joomla密碼看起來像這樣:
fbae378704687625a410223a61c66eb1:VM6DwmVWHTwpquDq51ZXjWWADCIc93MR
我相信md5(或其他東西)和單向加密? 我只是在尋找各種PHP代碼來創建相同的加密。
干杯
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword("yourpassword", $salt);
$password = $crypt.':'.$salt;
經過一番搜索,我找到了答案,謝謝你的幫助:)
編輯:我忘了提到你需要在調用JUserHelper之前包含這一行:
jimport( 'joomla.user.helper');
來自joomla論壇,這就是背后發生的事情:
例:
+1用於存儲密碼的哈希值,而不是存儲密碼本身。
為防止預計算攻擊,您應該使用隨機鹽。 另外,使用更強大的散列算法(如SHA-256)可能是一個好主意,我認為它支持PHP。 有關更多信息,請參閱用於PHP密碼的Secure hash和salt 。
我不懂PHP,但是大多數語言都有一個支持md5的庫和(以及其他哈希算法),PHP似乎也是如此。 我找到了這個:
string md5 ( string $str [, bool $raw_output = false ] )
使用»RSA Data Security,Inc。MD5消息摘要算法計算str的MD5哈希值,並返回該哈希值。
這是一個例子:
<?php
$password = 'apple';
if (md5($password) === '1f3870be274f6c49b3e31a0c6728957f') {
echo "Password correct";
}
?>
您可以轉到/libraries/joomla/user
並查看user.php
的bind()
函數
注冊時間內創建的所有用戶密碼都將在此處。
//function to encrypt the string
function encode5t($str)
{
for($i=0; $i<5;$i++)
{
$str=strrev(base64_encode($str)); //apply base64 first and then reverse the string
}
return $str;
}
//function to decrypt the string
function decode5t($str)
{
for($i=0; $i<5;$i++)
{
$str=base64_decode(strrev($str)); //apply base64 first and then reverse the string}
}
return $str;
}
在這個函數中,我使用base64_encode對字符串進行了5次加密,並使用strrev()反轉字符串,並通過首先反轉字符串然后應用base64_decode()來解密5次。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.