来自外部应用程序的 Joomla 登录身份验证 [英] Joomla Login Authentication from external app
问题描述
我需要从我的外部应用程序中检查 Joomla 用户名 和密码 是否有效.用户不必在其帐户存在时登录系统.我该怎么做?
I need to check that a Joomla username and password is valid from my external application. It is not necessary that the user is logged into the system just that their account exists. How do I do this?
推荐答案
我假设您的外部应用程序可以访问 Joomla 的数据库,并且也是用 php 编写的.
I'm supposing your external application will have access to Joomla's database and is written in php as well.
我已经回答了一个关于 在 joomla 之外创建用户,您可以使用相同的方法,但不是从 JUser
调用 save
方法,你可以使用bind
来检查密码是否正确.
I've already answered a similar question about creating a user outside joomla, you could use the same approach, but instead of calling the save
method from JUser
, you could use bind
to check if the password is correct.
或者更好的:在创建Joomla 外的环境"!检查JOOMLA_PATH/plugins/authentication/joomla.php
:
function onAuthenticate( $credentials, $options, &$response ){
jimport('joomla.user.helper');
// Joomla does not like blank passwords
if (empty($credentials['password'])){
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'Empty password not allowed';
return false;
}
// Initialize variables
$conditions = '';
// Get a database object
$db =& JFactory::getDBO();
$query = 'SELECT `id`, `password`, `gid`'
. ' FROM `#__users`'
. ' WHERE username=' . $db->Quote( $credentials['username'] )
;
$db->setQuery( $query );
$result = $db->loadObject();
if($result){
$parts = explode( ':', $result->password );
$crypt = $parts[0];
$salt = @$parts[1];
$testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
if ($crypt == $testcrypt) {
$user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
$response->email = $user->email;
$response->fullname = $user->name;
$response->status = JAUTHENTICATE_STATUS_SUCCESS;
$response->error_message = '';
} else {
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'Invalid password';
}
}
else{
$response->status = JAUTHENTICATE_STATUS_FAILURE;
$response->error_message = 'User does not exist';
}
}
这篇关于来自外部应用程序的 Joomla 登录身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!