Source for file joomla.php
Documentation is available at joomla.php
* @subpackage Authentication.joomla
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
* Joomla Authentication plugin
* @subpackage Authentication.joomla
* This method should handle any authentication and report back to the subject
* @param array $credentials Array holding the user credentials
* @param array $options Array of extra options
* @param object &$response Authentication response object
$response->type =
'Joomla';
// Joomla does not like blank passwords
if (empty($credentials['password']))
$response->error_message =
JText::_('JGLOBAL_AUTH_EMPTY_PASS_NOT_ALLOWED');
$query =
$db->getQuery(true)
->where('username=' .
$db->quote($credentials['username']));
$result =
$db->loadObject();
if (substr($result->password, 0, 4) ==
'$2y$')
// BCrypt passwords are always 60 characters, but it is possible that salt is appended although non standard.
$password60 =
substr($result->password, 0, 60);
elseif (substr($result->password, 0, 8) ==
'{SHA256}')
$parts =
explode(':', $result->password);
if ($result->password ==
$testcrypt)
$parts =
explode(':', $result->password);
if ($crypt ==
$testcrypt)
if (isset
($match) &&
$match ===
true)
// Bring this in line with the rest of the system
$response->email =
$user->email;
$response->fullname =
$user->name;
$response->language =
$user->getParam('admin_language');
$response->language =
$user->getParam('language');
$response->error_message =
'';
$response->error_message =
JText::_('JGLOBAL_AUTH_INVALID_PASS');
$response->error_message =
JText::_('JGLOBAL_AUTH_NO_USER');
// Check the two factor authentication
if (count($methods) <=
1)
// No two factor authentication method is enabled
// Load the user's OTP (one time password, a.k.a. two factor auth) configuration
$otpConfig =
$model->getOtpConfig($result->id);
$options['otp_config'] =
$otpConfig;
$otpConfig =
$options['otp_config'];
// Check if the user has enabled two factor authentication
if (empty($otpConfig->method) ||
($otpConfig->method ==
'none'))
// Warn the user if he's using a secret code but he has not
// enabed two factor auth in his account.
if (!empty($credentials['secretkey']))
$app->enqueueMessage(JText::_('PLG_AUTH_JOOMLA_ERR_SECRET_CODE_WITHOUT_TFA'), 'warning');
// This happens when we are in CLI mode. In this case
// Load the Joomla! RAD layer
// Try to validate the OTP
$otpAuthReplies =
FOFPlatform::getInstance()->runPlugins('onUserTwofactorAuthenticate', array($credentials, $options));
* This looks like noob code but DO NOT TOUCH IT and do not convert
* to in_array(). During testing in_array() inexplicably returned
* null when the OTEP begins with a zero! o_O
if (!empty($otpAuthReplies))
foreach ($otpAuthReplies as $authReply)
$check =
$check ||
$authReply;
// Fall back to one time emergency passwords
// Did the user use an OTEP instead?
if (empty($otpConfig->otep))
if (empty($otpConfig->method) ||
($otpConfig->method ==
'none'))
// Two factor authentication is not enabled on this account.
// Any string is assumed to be a valid OTEP.
* Two factor authentication enabled and no OTEPs defined. The
* user has used them all up. Therefore anything he enters is
// Clean up the OTEP (remove dashes, spaces and other funny stuff
// our beloved users may have unwittingly stuffed in it)
$otep =
$credentials['secretkey'];
$otep =
filter_var($otep, FILTER_SANITIZE_NUMBER_INT);
// Did we find a valid OTEP?
// Remove the OTEP from the array
$otpConfig->otep =
array_diff($otpConfig->otep, array($otep));
$model->setOtpConfig($result->id, $otpConfig);
// Return true; the OTEP was a valid one
$response->error_message =
JText::_('JGLOBAL_AUTH_INVALID_SECRETKEY');
Documentation generated on Tue, 19 Nov 2013 15:06:08 +0100 by phpDocumentor 1.4.3