[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/plugins/authentication/ -> joomla.php (source)

   1  <?php
   2  /**
   3  * @version        $Id: joomla.php 14401 2010-01-26 14:10:00Z louis $
   4  * @package        Joomla
   5  * @subpackage    JFramework
   6  * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7  * @license        GNU/GPL, see LICENSE.php
   8  * Joomla! is free software. This version may have been modified pursuant
   9  * to the GNU General Public License, and as distributed it includes or
  10  * is derivative of works licensed under the GNU General Public License or
  11  * other free or open source software licenses.
  12  * See COPYRIGHT.php for copyright notices and details.
  13  */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport( 'joomla.plugin.plugin' );
  19  
  20  /**
  21   * Joomla Authentication plugin
  22   *
  23   * @package        Joomla
  24   * @subpackage    JFramework
  25   * @since 1.5
  26   */
  27  class plgAuthenticationJoomla extends JPlugin
  28  {
  29  
  30      /**
  31       * Constructor
  32       *
  33       * For php4 compatability we must not use the __constructor as a constructor for plugins
  34       * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
  35       * This causes problems with cross-referencing necessary for the observer design pattern.
  36       *
  37       * @param object $subject The object to observe
  38       * @param array  $config  An array that holds the plugin configuration
  39       * @since 1.5
  40       */
  41  	function plgAuthenticationJoomla(& $subject, $config) {
  42          parent::__construct($subject, $config);
  43      }
  44  
  45      /**
  46       * This method should handle any authentication and report back to the subject
  47       *
  48       * @access    public
  49       * @param   array     $credentials Array holding the user credentials
  50       * @param     array   $options     Array of extra options
  51       * @param    object    $response     Authentication response object
  52       * @return    boolean
  53       * @since 1.5
  54       */
  55  	function onAuthenticate( $credentials, $options, &$response )
  56      {
  57          jimport('joomla.user.helper');
  58  
  59          // Joomla does not like blank passwords
  60          if (empty($credentials['password']))
  61          {
  62              $response->status = JAUTHENTICATE_STATUS_FAILURE;
  63              $response->error_message = 'Empty password not allowed';
  64              return false;
  65          }
  66  
  67          // Initialize variables
  68          $conditions = '';
  69  
  70          // Get a database object
  71          $db =& JFactory::getDBO();
  72  
  73          $query = 'SELECT `id`, `password`, `gid`'
  74              . ' FROM `#__users`'
  75              . ' WHERE username=' . $db->Quote( $credentials['username'] )
  76              ;
  77          $db->setQuery( $query );
  78          $result = $db->loadObject();
  79  
  80  
  81          if($result)
  82          {
  83              $parts    = explode( ':', $result->password );
  84              $crypt    = $parts[0];
  85              $salt    = @$parts[1];
  86              $testcrypt = JUserHelper::getCryptedPassword($credentials['password'], $salt);
  87  
  88              if ($crypt == $testcrypt) {
  89                  $user = JUser::getInstance($result->id); // Bring this in line with the rest of the system
  90                  $response->email = $user->email;
  91                  $response->fullname = $user->name;
  92                  $response->status = JAUTHENTICATE_STATUS_SUCCESS;
  93                  $response->error_message = '';
  94              } else {
  95                  $response->status = JAUTHENTICATE_STATUS_FAILURE;
  96                  $response->error_message = 'Invalid password';
  97              }
  98          }
  99          else
 100          {
 101              $response->status = JAUTHENTICATE_STATUS_FAILURE;
 102              $response->error_message = 'User does not exist';
 103          }
 104      }
 105  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1