问题描述
我需要检查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.
我已经回答了有关,您可以使用相同的方法,但是可以使用bind
来检查是否从JUser
调用save
密码正确.
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_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登录身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!