0

我正在为我的雇主开发一个网站。我们目前有一个 Joomla!1.5 网站,并且正在完全重新设计和升级到 Joomla!2.5

我们将Authentication - ExtDB插件用于当前站点。此后,该插件似乎已被放弃(或至少未更新)。

是否有任何插件可以让我们使用我们的 MySQL 数据库进行身份验证?我在一些网站上读到,可以通过破解核心 Joomla!登录功能,但我宁愿避免这种情况。

如果有人有任何意见或建议,将不胜感激。

谢谢你。

编辑:

据我所知,我已经更新了*.xml*.php安装工作。我现在的问题是,当我尝试使用新插件时,出现以下错误:

JAuthentication: :authenticate: Failed to load plugin: plgauthenticationmysql

我错过了关键的一步吗?

XML:

    <files>
        <filename plugin="mysql">mysql-auth.php</filename>
        <filename>index.html</filename>
    </files>
    <config>
        <fields name="params">
            <fieldset name="basic">
                <field name="backend_login" type="radio" default="0" label="Enable Backend Login" description="Enable backend login for the external users" >
                    <option value="1">Yes</option>
                    <option value="0">No</option>
                </field>
                <field name="@spacer" type="spacer" default="" label="" description="" />
                <field name="host" type="text" size="20" default="" label="Database Host" description="PARAMDBHOST" />
                <field name="port" type="text" size="20" default="3306" label="Server Port" description="PARAMDBPORT" />
                <field name="connectuser" type="text" size="20" default="" label="Connect username" description="PARAMCONNECTUSER" />
                <field name="connectpassword" type="password" size="20" default="" label="Connect password" description="PARAMCONNECTPASSWORD" />
                <field name="db_type" default="MySQL" type="list" label="Database Type" description="PARAMDBTYPE">
                    <option value="mysql">MySQL</option>
                </field>
                <field name="@spacer" type="spacer" default="" label="" description="" />
                <field name="dbname" type="text" size="20" default="" label="Database name" description="PARAMDBNAME" />
                <field name="table" type="text" size="20" default="" label="Table name" description="PARAMTABLE" />
                <field name="usernamefield" type="text" size="20" default="" label="Username Field" description="PARAMUSERFIELD" />
                <field name="passwordfield" type="text" size="20" default="" label="Password Field" description="PARAMPASSWORDFIELD" />
                <field name="passwordtype" default="MD5" type="list" label="Password Type" description="PARAMPWDTYPE">
                    <option value="MD5">MD5</option>
                    <option value="SHA1">SHA-1</option>
                    <option value="CRYPT">CRYPT (Linux only)</option>
                    <option value="PLAIN">Plain Text</option>
                </field>
                <field name="passwordsalt" type="text" size="20" default="" label="Password Salt" description="PARAMPASSWORDSALT" />
                <field name="@spacer" type="spacer" default="" label="" description="" />
                <field name="firstnamefield" type="text" size="20" default="" label="First name Field" description="PARAMFIRSTNAMEFIELD" />
                <field name="surnamefield" type="text" size="20" default="" label="Surname Field" description="PARAMSURNAMRFIELD" />
                <field name="emailfield" type="text" size="20" default="" label="e-mail Field" description="PARAMEMAILFIELD" />
            </fieldset>
        </fields>
    </config>

PHP:

<?php
    defined('_JEXEC') or die();

    jimport('joomla.event.plugin');

    class plgAuthenticationMySQL extends JPlugin
    {
    function plgAuthenticationMySQL(& $subject, $config){
        parent::__construct($subject, $config);
        $this->loadLanguage();
    }
    function onUserAuthenticate( $credentials, $options, & $response )
    {
        $mode = $this->params->def('mode', 1);

        if(stripos($options['entry_url'], 'administrator') ){
            if ( (strcasecmp($options['group'], 'Public Backend') == 1) || ($params->get('backend_login') == 0) ){
                $response->status = JAuthentication::STATUS_FAILURE;
                $response->error_message = "You are not allow to login here.";
                return false;
            }
        }

        $driver = $params->get('db_type'); 
        $port = $params->get('port'); 
        if($port == '3306')
            $host   = $params->get('host');
        else
            $host   = $params->get('host').':'.$port;

        $user = $params->get('connectuser');            
        $pass = $params->get('connectpassword');        
        $dbase = $params->get('dbname');             
        $table = $params->get('table');                 
        $usernamefield = $params->get('usernamefield'); 
        $passwordfield = $params->get('passwordfield');   
        $passwordtype = $params->get('passwordtype');     
        $passwordsalt = $params->get('passwordsalt');     
        $firstnamefield = $params->get('firstnamefield'); 
        $surnamefield = $params->get('surnamefield');     
        $emailfield = $params->get('emailfield');        

    // Connect to the database host
        if(!($db = mysql_connect($host, $user, $pass, true)))
        {
            $response->status = JAuthentication::STATUS_FAILURE;
            $response->error_message = "Cant connect to the remote host: $host";
            return false;
        }

    if(!mysql_select_db($dbase, $db))
        {
            $response->status = JAuthentication::STATUS_FAILURE;
            $response->error_message = "Cant connect to the remote database: $dbase";
            return false;
        }

    switch ($passwordtype) {
            case 'MD5':
                $password = md5($credentials['password'].$passwordsalt);
                break;
            case 'SHA1':
                $password = sha1($credentials['password'].$passwordsalt);
                break;
            case 'CRYPT': 
                break; 
            case 'PLAIN':
                $password = $credentials['password'];
                break;
            default:
                $password = md5($credentials['password'].$passwordsalt);
                break;
        }

        $query = "SELECT `$usernamefield`" ;
        if ($firstnamefield)
            $query .= ",`$firstnamefield`";
        if ($surnamefield)
            $query .= ",`$surnamefield`";
        if ($emailfield)
            $query .= ",`$emailfield`";

        $query .= sprintf(" FROM `%s` WHERE `%s`='%s'", $table, $usernamefield, $credentials['username']);

    if ($passwordtype === 'CRYPT')
            $query .= sprintf(" AND ENCRYPT('%s', `%s`)=`%s`", $credentials['password'], $passwordfield, $passwordfield);
        else
            $query .= sprintf(" AND `%s` = '%s'", $passwordfield, $password);

        $result = mysql_query($query);
        $result_ar = mysql_fetch_assoc($result);

        mysql_close($db);

        if (!$result_ar) {
            $response->status = JAuthentication::STATUS_FAILURE;
            $response->error_message = 'Invalid User Name or Password';
            return false;
        }

        $response->username = $result_ar[$usernamefield];

        if ($firstnamefield and $surnamefield)
            $response->fullname = $result_ar[$firstnamefield] . " " . $result_ar[$surnamefield];
        else if ($firstnamefield)
            $response->fullname = $result_ar[$firstnamefield];
        else if ($surnamefield)
            $response->fullname = $result_ar[$surnamefield];

        if ($emailfield)
            $response->email = $result_ar[$emailfield];

            $record = JUser::getInstance(); 
        if (!$response->fullname)
            $response->fullname = 'No full name :)';
        if (!$response->email)
            $response->email = 'noemail@nodomain.none';

        $response->status = JAuthentication::STATUS_SUCCESS;

        return true;
    }
}
?>
4

0 回答 0