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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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/

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web-Based CMS

From novice to tech pro — start learning today.