Creating a Joomla 1.5 Authentication Plugin to Authenticate Against an IMAP Server

I'm trying to authenticate users against an IMAP server in Joomla!  I found a basic php script to do this (see below), but trying to implement it into Joomla! (with the help of this tutorial: http://docs.joomla.org/Tutorial:Creating_an_Authentication_Plugin_for_Joomla_1.5), I keep on hitting a wall.
 I'm not sure iIf Joomla! is even using this custom plugin, and if it is, why is it failing? Front-end login produces the following error:Username and password do not match or you do not have an account yet.
The plugin installed without errors, and I activated it in the Joomla! Administrator's Plugin Manager, and disabled the default Jooma! authentication plugin.  Below is the original (very simple) authentication script, followed by the Joomla! authentication script.  
<?
//The original script, which works with no problem.
function auth_imap($username, $password)
    {
        
 
        $mbox = imap_open("{imap.roshcon.co.za:143}", $username, $password);
 
        if ($mbox === false) {
            $msg="access denied";
        } else {
      	    $ignored = imap_errors(); // ignore "mailbox is empty" notice
            imap_close($mbox);
            $msg="access granted";
        }
		return $msg;
    }
	
	
	?>
----------------------------------------------------------------------
// Script as implemented in myAuth.php which is the Joomla! plugin
 
<?php
/**
 * @version    $Id: myauth.php 7180 2007-04-23 16:51:53Z jinx $
 * @package    Joomla.Tutorials
 * @subpackage Plugins
 * @license    GNU/GPL
 */
 
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();
 
jimport('joomla.event.plugin');
 
/**
 * Example Authentication Plugin.  Based on the example.php plugin in the Joomla! Core installation
 *
 * @package    Joomla.Tutorials
 * @subpackage Plugins
 * @license    GNU/GPL
 */
class plgAuthenticationMyauth extends JPlugin
{
    /**
     * Constructor
     *
     * For php4 compatability we must not use the __constructor as a constructor for plugins
     * because func_get_args ( void ) returns a copy of all passed arguments NOT references.
     * This causes problems with cross-referencing necessary for the observer design pattern.
     *
     * @param object $subject The object to observe
     * @since 1.5
     */
    function plgAuthenticationMyauth(& $subject) {
        parent::__construct($subject);
    }
 
    /**
     * This method should handle any authentication and report back to the subject
     * This example uses simple authentication - it checks if the password is the reverse
     * of the username (and the user exists in the database).
     *
     * @access    public
     * @param    string    $username    Username for authentication
     * @param    string    $password    Password for authentication
     * @param    object    $response    Authentication response object
     * @return    boolean
     * @since 1.5
     */
    function onAuthenticate( $username, $password, &$response )
    {
		$mbox = imap_open("{imap.roshcon.co.za:143}", $username, $password);
 
        if ($mbox === false) {
             $response->status = JAUTHENTICATE_STATUS_FAILURE;
            $response->error_message = 'Invalid username and password';
        } else {
      	    $ignored = imap_errors(); // ignore "mailbox is empty" notice
            imap_close($mbox);
            $email = JUser::getInstance($result); // Bring this in line with the rest of the system
            $response->email = $email->email;
            $response->status = JAUTHENTICATE_STATUS_SUCCESS;
			
        }
		
    }
        }
?>

Open in new window

benjaminzAsked:
Who is Participating?
 
HuyBDCommented:
i think we should not never re-use or extend on joomla framework, we just use joomla for cms, then we extend joomla by write our self component, that help us not depend to much on joomla.
pls see:
http://www.jlleblanc.com/joomla/Tutorials/The_Daily_Message_Joomla_Component_Tutorial/
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.