Red*_*Red 34 php joomla md5 codeigniter
我需要jos_users从外部php脚本[codeignitor] 访问joomla用户表以进行登录检查.
joomla存储这样的密码
4e9e4bcc5752d6f939aedb42408fd3aa:0vURRbyY8Ea0tlvnTFn7xcKpjTFyn0YT
看起来这不是正常的MD5,所以我无法使用md5(password).
创建密码的可能方法是什么?
谢谢.
kle*_*tte 62
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
现在使用此salt和myguy输入的密码计算哈希值
$userhash = md5($userpassword.$hashparts[1]); // This would be 'mypassword' and the salt used in the original hash
现在如果这个$userhash和$hashparts[0]相同,则用户输入了正确的密码.
小智 22
来自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 
盐是随机的32个字符串.
谢谢
在joomla标准中,您可以使用以下方式创建密码
                     jimport('joomla.user.helper');
             $salt = JUserHelper::genRandomPassword(32);
             $crypt = JUserHelper::getCryptedPassword($password_choose, $salt);
             $password = $crypt.':'.$salt;
你提到你正在从外部文件(或程序)访问,那么如果你在另一边安装了joomla,你可以从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();