简体   繁体   English

Joomla 3.2.1密码加密

[英]Joomla 3.2.1 password encryption

When the user register on the site , and I look in the database joomla_users in the password table, there are password stored in the following formats: 当用户在网站上注册时,我在密码表中查看数据库joomla_users,有以下格式存储的密码:

  • $P$Do8QrURFT1r0NlWf0X/grdF/aMqwqK/ $ P $ Do8QrURFT1r0NlWf0X / GRDF / aMqwqK /

  • $P$DH38Lch9z508gJiop3A6u0whTity390 $ P $ DH38Lch9z508gJiop3A6u0whTity390

  • ........ ........

But not in the form as described in the documentation (MD5 + ":" + SALT): 但不是文档中描述的形式(MD5 +“:”+ SALT):

  • 1802ebc64051d5b4f4d1b408babb5020:0PHJDbnsyX05YpKbAuLYnw2VCzFMW2VK 1802ebc64051d5b4f4d1b408babb5020:0PHJDbnsyX05YpKbAuLYnw2VCzFMW2VK

I need to have this clarified for me, because I'm using outside script that checks for user credentials to check for password match. 我需要为我澄清这一点,因为我使用外部脚本检查用户凭据以检查密码匹配。

In my PHP script I have code that seperates SALT from password from database: 在我的PHP脚本中,我有代码从数据库中的密码中分离SALT:

$parts   = explode( ':', $password_database );
$crypt   = $parts[0];
$salt   = $parts[1];

But I can't do that if there is no dobule knot (:) 但如果没有dobule结(:),我不能这样做

Try this, 试试这个,

The following piece of code is creating Joomla standard password (Older Version 1.5,1.7 etc) . 下面的代码是创建Joomla标准密码(旧版本1.5,1.7等)

 jimport('joomla.user.helper');
 $salt = JUserHelper::genRandomPassword(32);
 $crypt = JUserHelper::getCryptedPassword($password_choose, $salt);
 $password = $crypt.':'.$salt;

Joomla 3.2+ introduced PHP's password algorithm bcrypt but it required a minimum PHP 5.3+ If you plan to use bcrypt make sure your server PHP version is capable for this, read more here . Joomla 3.2+引入了PHP的密码算法bcrypt,但它需要最低的PHP 5.3+如果您打算使用bcrypt,请确保您的服务器PHP版本具备此功能, 请在此处阅读更多内容

The other Version of Joomla Using the following methods ( Joomla 3.x ) Joomla的另一个版本使用以下方法( Joomla 3.x

 jimport('joomla.user.helper');
 $yourpass = JUserHelper::hashPassword($password_choose);

The older algorithm also works fine in latest version too , only difference is older version creates a 65 character password and new one creates 34 character string. 旧算法也可以在最新版本中正常工作,唯一不同的是旧版本创建65个字符的密码而新的创建34个字符串。 always go with updated version 总是使用更新版本

Also if you are using external script should include Joomla framework like below. 此外,如果您使用外部脚本应包括如下所示的Joomla框架。 This should at very top of your external php file 这应该在你的外部PHP文件的顶部

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();

Also you mentioned you have to check users credential then no need to check password format and all thing just use below codes after framework loads. 你还提到你必须检查用户凭证,然后不需要检查密码格式,所有的东西只是在框架加载后使用下面的代码。

   $credentials['username'] = $data['username']; //user entered name
   $credentials['password'] = $data['password']; //users entered password
   $app = JFactory::getApplication();
   $error = $app->login($credentials, $options);
   if (!JError::isError($error)) {
    // login success
    }
  else{
    //Failed attempt
   }

hope it helps.. 希望能帮助到你..

Joomla's default user class no longer uses salted MD5 to hash the password. Joomla的默认用户类不再使用salted MD5来散列密码。 The bind function of the JUser class now calls JUserHelper::hashPassword($array['password']) to encrypt the password. JUser类的绑定函数现在调用JUserHelper::hashPassword($array['password'])来加密密码。

That function is currently this: 该功能目前是这样的:

public static function hashPassword($password)
    {
            // Use PHPass's portable hashes with a cost of 10.
            $phpass = new PasswordHash(10, true);

            return $phpass->HashPassword($password);
    }

And that means that it now relies on PHPass which you can read more about here: http://www.openwall.com/phpass/ . 这意味着它现在依赖于PHPass,您可以在这里阅读更多信息: http//www.openwall.com/phpass/ Based on reading just the intro of this site, I'm guessing that the encryption is now bcrypt instead of MD5, but Joomla may have overriden the default encryption. 基于阅读本网站的介绍,我猜测加密现在是bcrypt而不是MD5,但Joomla可能已经覆盖了默认加密。

With David Fritsch answer I get to do a encrypted password as Joomla does: 有了David Fritsch的回答,我可以像Joomla那样做一个加密的密码:

<?php
    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();

    jimport('joomla.user.helper');
    $password = "test";     
    echo "<strong>Password: </strong>" . JUserHelper::hashPassword($password);
?>

Note that you have to store the file in joomla root directory, or change JPATH_BASE. 请注意,您必须将文件存储在joomla根目录中,或更改JPATH_BASE。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM