php - Joomla 3.2.1密码加密

标签 php joomla password-hash

当用户在网站上注册时,我查看数据库 joomla_users 中的密码表,有以下格式存储的密码:

  • $P$Do8QrURFT1r0NlWf0X/grdF/aMqwqK/

  • $P$DH38Lch9z508gJiop3A6u0whTity390

  • ........

但不是文档中描述的形式(MD5 + ":"+ SALT):

  • 1802ebc64051d5b4f4d1b408babb5020:0PHJDbnsyX05YpKbAuLYnw2VCzFMW2VK

我需要为我澄清这一点,因为我正在使用检查用户凭据的外部脚本来检查密码匹配。

在我的 PHP 脚本中,我有代码将 SALT 与来自数据库的密码分开:

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

但是如果没有双结我就做不到了(:)

最佳答案

试试这个,

下面的一段代码正在创建 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+ 引入了 PHP 的密码算法 bcrypt 但它至少需要 PHP 5.3+ 如果您打算使用 bcrypt 确保您的服务器 PHP 版本支持此功能,read more here .

使用以下方法的其他版本的 Joomla (Joomla 3.x)

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

旧算法在最新版本中也能正常工作,唯一的区别是旧版本创建 65 个字符的密码,而新版本创建 34 个字符的字符串。始终使用更新版本

此外,如果您使用的是外部脚本,则应包括如下所示的 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();

您还提到您必须检查用户凭据,然后无需检查密码格式,所有内容都只需在框架加载后使用下面的代码。

   $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
   }

希望对你有帮助

关于php - Joomla 3.2.1密码加密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21304038/

相关文章:

templates - Joomla,单个模板中的多个布局

Joomla:博客中的新闻

mysql - MySQL流量的Wireshark密码捕获

php - 在 mysql MyISAM 表中同时更新计数器

php - 带有 Xdebug 的 VS Code 不显示完整的 PHP 变量值

php - Eloquent Join - where 关闭

entity-framework - 如何在外部管理(添加)ASP.NET Core 3.1 应用程序的用户

php - WordPress 帖子元上传框中的 $_FILES 始终为空

Joomla 3 - 如何从配置文件中获取值(value)?

php - 如何使用PHP的password_hash来哈希和验证密码