我需要訪問joomla用戶表jos_users
用於從外部php腳本[codeignitor]進行登錄檢查。joomla密碼加密
的Joomla存儲密碼,這樣
4e9e4bcc5752d6f939aedb42408fd3aa:0vURRbyY8Ea0tlvnTFn7xcKpjTFyn0YT
看起來這是不正常的MD5,所以我不能使用md5(password)
。
什麼是創建密碼的可能方式?
謝謝。
我需要訪問joomla用戶表jos_users
用於從外部php腳本[codeignitor]進行登錄檢查。joomla密碼加密
的Joomla存儲密碼,這樣
4e9e4bcc5752d6f939aedb42408fd3aa:0vURRbyY8Ea0tlvnTFn7xcKpjTFyn0YT
看起來這是不正常的MD5,所以我不能使用md5(password)
。
什麼是創建密碼的可能方式?
謝謝。
Joomla密碼是MD5哈希值,但密碼在哈希前被醃製。 它們作爲{hash}:{salt}
存儲在數據庫中,這個鹽是一個隨機字符串,長度爲32個字符。
所以要創建一個新的密碼哈希你會做md5($password.$salt)
編輯
好了,檢查密碼,說用戶myguy
輸入密碼mypassword
,你會從數據庫中檢索行用戶名爲myguy
。
在這一行中,您會發現密碼爲4e9e4bcc5752d6f939aedb42408fd3aa:0vURRbyY8Ea0tlvnTFn7xcKpjTFyn0YT
。 你分手了密碼哈希和鹽:
$hashparts = preg_split (':' , $dbpassword);
echo $hashparts[0]; //this is the hash 4e9e4bcc5752d6f939aedb42408fd3aa
echo $hashparts[1]; //this is the salt 0vURRbyY8Ea0tlvnTFn7xcKpjTFyn0YT
現在使用這種鹽計算散列和myguy
進入
$userhash = md5($userpassword.$hashparts[1]); // This would be 'mypassword' and the salt used in the original hash
現在,如果這個$userhash
和$hashparts[0]
是相同的用戶輸入的密碼正確的密碼。
我怎樣才能得到'$ salt'? – Red
對於現有的密碼,只需在':'鹽之後的字符串。要創建一個新的密碼salt,只需生成一個隨機字符串。如呃。 Anurag Jain在他的回答中說,你可以用'JUserHelper :: genRandomPassword(32)' – klennepette
輕鬆做到這一點。對不起,但我仍然無法找到問題的答案,假設用戶有一個傳遞'你好',但我怎麼知道隨機數?它的生成和由JOOMLA存儲在分貝.. – Red
從的Joomla論壇,這背後究竟發生了:
A. Generate a password
B. Generate a string with 32 random characters
C. Concatenate Password (Step A) and RandomString (Step B)
D. Take md5(Result of Step C)
E. store Step D Result : Step B Result
例子:
Generate a password - Let 'testing'
Generate a string of 32 random characters - 'aNs1L5PajsIscupUskaNdPenustelsPe'
Concatenate Password and random string - testingaNs1L5PajsIscupUskaNdPenustelsPe
md5(Step C Result) - 5cf56p85sf15lpyf30c3fd19819p58ly
store step d:step B - 5cf56p85sf15lpyf30c3fd19819p58ly:aNs1L5PajsIscupUskaNdPenustelsPe
你可以找到代碼中的Joomla像
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword("testing", $salt);
$password = $crypt . ':' . $salt;
或者我們可以說
password DB field = md5(password + salt) + ":" + salt
其中salt是隨機的32個字符串。
感謝
在的Joomla標準,你可以使用你提到你是從外部文件(或程序)訪問下列方式
jimport('joomla.user.helper');
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($password_choose, $salt);
$password = $crypt.':'.$salt;
創建密碼,然後,如果你對對方的Joomla安裝你可以從joomla結構之外訪問它。
這樣
define('_JEXEC', 1);
define('JPATH_BASE', dirname(__FILE__));//this is when we are in the root
define('DS', DIRECTORY_SEPARATOR);
require_once (JPATH_BASE .DS.'includes'.DS.'defines.php');
require_once (JPATH_BASE .DS.'includes'.DS.'framework.php');
$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();
http://stackoverflow.com/questions/10409432/access-joomla-session -in-php-codeigniter - 這個問題還沒有回答:) – Red
使用Joomla默認框架的工作,我不能用preg_split
但explode
效果很好。
$hashparts = explode (':' , $dbpassword);
如果只是用MD5($密碼);它會工作,嘗試它。 Joomla有一個機制,它可以處理多種類型的密碼(包括最近的強密碼)。你不必擔心冒號後的部分。只需使用md5($密碼),它肯定會工作。
順便說一下,這也將在Joomla 3.x上工作。
從joomla源文件庫/ joomla/crypt/password/simple.php有多種方式存儲,有些沒有':'字符。
switch ($type)
{
case '$2a$':
case JCryptPassword::BLOWFISH:
if (JCrypt::hasStrongPasswordSupport())
{
$type = '$2y$';
}
else
{
$type = '$2a$';
}
$salt = $type . str_pad($this->cost, 2, '0', STR_PAD_LEFT) . '$' . $this->getSalt(22);
return crypt($password, $salt);
case JCryptPassword::MD5:
$salt = $this->getSalt(12);
$salt = '$1$' . $salt;
return crypt($password, $salt);
case JCryptPassword::JOOMLA:
$salt = $this->getSalt(32);
return md5($password . $salt) . ':' . $salt;
}
}
Joomla!使用PhPass。
root/libraries/phpass/PasswordHash.php
看看這裏。你會在這裏看到密碼是如何產生的。
的$ 2Y是默認的(和優選的)前綴上bcrypt散列。 至於代碼,你會想看看JUserHelper's
hashPassword
和verifyPassword
方法,看看Joomla如何處理現在的事情。
https://github.com/joomla/joomla-cms/blob/3.4.1/libraries/joomla/user/helper.php#L296-L387
https://docs.joomla.org/API15:JUserHelper/getCryptedPassword
https://docs.joomla.org/API15:JUserHelper/getSalt
檢查環節,我希望你它會有所幫助:)
ya看起來像joomla v3.2.2他們已經切換到phpass – user889030
<?php
$r = bin2hex(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM));
$p = 'the_password';
$s = $p . $r;
$m = md5($s);
$out = $m . ':' . $r;
echo $out;
Len 16因爲bin2hex使字符大小增加一倍,因爲1字節變爲2字節
深層問題:)如果您仍然認爲md5是存儲密碼的正常方式,那麼您可能需要對該問題做更多的研究 – mishu
僅供參考,不應將MD5用於哈希密碼。永遠。特別是在你的例子中沒有鹽。 – tangrs
感謝您的信息;但在這裏我不想生成密碼字段。 – Red