?
Solved

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

Posted on 2008-11-05
2
Medium Priority
?
2,776 Views
Last Modified: 2008-12-31
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

0
Comment
Question by:benjaminz
1 Comment
 
LVL 17

Accepted Solution

by:
HuyBD earned 1200 total points
ID: 22892924
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question