我有一个api,将验证joomla用户,密码。虽然它在Joomla 2.5中运行良好,但它在Joomla 3.5中给出了Application Instantiation错误。代码部分如下:
function checkAuthentication($ username,$ password) {
jimport( 'joomla.user.authentication');
$auth = & JAuthentication::getInstance();
$credentials = array( 'username' => $username, 'password' => $password );
$options = array();
$response = $auth->authenticate($credentials, $options);
if ($response->status != JAUTHENTICATE_STATUS_SUCCESS)
{
echo "Failure";
}
else
{
echo "Success~" . $username;
}
}
$ auth =&行失败了JAuthentication ::的getInstance();
我已在配置文件中检查了所有配置,如数据库设置等。有人可以帮我找出原因。
答案 0 :(得分:1)
下面的代码可以解决这个问题 - 它是Joomla Authentication插件的修改版本(plugins / authentication / joomla / joomla.php)。
$query = $db->getQuery(true);
$query->select(array('id, 'password'));
$query->from('#__users');
$query->where($db->quoteName('username') . ' = ' . $db->quote($username));
$db->setQuery($query);
$result = $db->loadObject();
/*
* This block supports Joomla 3.2 upwards
*/
if ($result)
{
$match = JUserHelper::verifyPassword($password, $result->password, $result->id);
if ($match === true)
{
$user = JUser::getInstance($result->id);
$response->email = $user->email;
$response->fullname = $user->name;
if (JFactory::getApplication()->isAdmin())
{
$response->language = $user->getParam('admin_language');
}
else
{
$response->language = $user->getParam('language');
}
$response->status = JAuthentication::STATUS_SUCCESS;
$response->error_message = '';
}
else
{
// Invalid password
$response->status = JAuthentication::STATUS_FAILURE;
$response->error_message = JText::_('JGLOBAL_AUTH_INVALID_PASS');
}
}