API16

JAuthentication/authenticate

From Joomla! Documentation

< API16:JAuthentication
Revision as of 21:50, 12 May 2013 by JoomlaWikiBot (talk | contribs) (removing red link to edit, no existant pages)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Finds out if a set of login credentials are valid by asking all obvserving objects to run their respective authentication routines.

[<! removed edit link to red link >]

<! removed transcluded page call, red link never existed >

Syntax[edit]

authenticate($credentials, $options)
Parameter Name Default Value Description
$credentials Array holding the user credentials
$options

Returns[edit]

mixed Integer userid for valid user if credentials are valid or boolean false if they are not

Defined in[edit]

libraries/joomla/user/authentication.php

Importing[edit]

jimport( 'joomla.user.authentication' );

Source Body[edit]

public function authenticate($credentials, $options)
{
        // Initialise variables.
        $auth = false;

        // Get plugins
        $plugins = JPluginHelper::getPlugin('authentication');

        // Create authencication response
        $response = new JAuthenticationResponse();

        /*
         * Loop through the plugins and check of the creditials can be used to authenticate
         * the user
         *
         * Any errors raised in the plugin should be returned via the JAuthenticationResponse
         * and handled appropriately.
         */
        foreach ($plugins as $plugin)
        {
                $className = 'plg'.$plugin->type.$plugin->name;
                if (class_exists($className)) {
                        $plugin = new $className($this, (array)$plugin);
                }
                else {
                        // bail here if the plugin can't be created
                        JError::raiseWarning(50,'JAuthentication::authenticate: '. JText::_('Failed to load plugin') .': '. $className);
                        continue;
                }

                // Try to authenticate
                $plugin->onAuthenticate($credentials, $options, $response);

                // If authentication is successfull break out of the loop
                if ($response->status === JAUTHENTICATE_STATUS_SUCCESS)
                {
                        if (empty($response->type)) {
                                $response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name;
                        }
                        if (empty($response->username)) {
                                $response->username = $credentials['username'];
                        }

                        if (empty($response->fullname)) {
                                $response->fullname = $credentials['username'];
                        }

                        if (empty($response->password)) {
                                $response->password = $credentials['password'];
                        }

                        break;
                }
        }
        return $response;
}

[<! removed edit link to red link >] <! removed transcluded page call, red link never existed >

Examples[edit]

<CodeExamplesForm />