public \Joomla\CMS\Authentication\AuthenticationResponse
authenticate
(mixed $credentials, mixed $options = array())
/**
* Finds out if a set of login credentials are valid by asking all observing
* objects to run their respective authentication routines.
*
* @param array $credentials Array holding the user credentials.
* @param array $options Array holding user options.
*
* @return AuthenticationResponse Response object with status variable filled in for last plugin or first successful plugin.
*
* @see AuthenticationResponse
* @since 1.7.0
*/
public function authenticate($credentials, $options = array())
{
// Get plugins
$plugins = PluginHelper::getPlugin($this->pluginType);
// Create authentication response
$response = new AuthenticationResponse();
/*
* Loop through the plugins and check if the credentials can be used to authenticate
* the user
*
* Any errors raised in the plugin should be returned via the AuthenticationResponse
* and handled appropriately.
*/
foreach ($plugins as $plugin) {
$plugin = Factory::getApplication()->bootPlugin($plugin->name, $plugin->type);
if (!method_exists($plugin, 'onUserAuthenticate')) {
// Bail here if the plugin can't be created
Log::add(Text::sprintf('JLIB_USER_ERROR_AUTHENTICATION_FAILED_LOAD_PLUGIN', $plugin->name), Log::WARNING, 'jerror');
continue;
}
// Try to authenticate
$plugin->onUserAuthenticate($credentials, $options, $response);
// If authentication is successful break out of the loop
if ($response->status === self::STATUS_SUCCESS) {
if (empty($response->type)) {
$response->type = $plugin->_name ?? $plugin->name;
}
break;
}
}
if (empty($response->username)) {
$response->username = $credentials['username'];
}
if (empty($response->fullname)) {
$response->fullname = $credentials['username'];
}
if (empty($response->password) && isset($credentials['password'])) {
$response->password = $credentials['password'];
}
return $response;
}