We would like to use Zend_Auth Ldap Adapter for our web application
authentication process. The Ldap.php file have been download into
Zend/Auth/Adapter/ directory. Following is my AuthController class file to
authenticate against database Projects.Personnel table which stores in MySQL
DB. It works well. Now We would like to switch to Ldap server, Would anybody
give us some hints regarding how to do that? Thanks in advance.

AuthController.php file:
<?php

class AuthController extends Zend_Controller_Action
{
    function init()
    {
        $this->initView();
        $this->view->baseUrl = $this->_request->getBaseUrl();
    }
       
    function indexAction()
    {
        $this->_redirect('/');
    }
   
    function loginAction()
    {
        $this->view->message = '';
        if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') {
            // collect the data from the user
            Zend_Loader::loadClass('Zend_Filter_StripTags');
            $filter = new Zend_Filter_StripTags();
            $username =
$filter->filter($this->_request->getPost('username'));
            $password =
md5($filter->filter($this->_request->getPost('password')));

            if (empty($username)) {
                $this->view->message = 'Please provide a username.';
            } else {
                // setup Zend_Auth adapter for a database table
                Zend_Loader::loadClass('Zend_Auth_Adapter_DbTable');
                $dbAdapter = Zend_Registry::get('dbAdapter');
                $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
                $authAdapter->setTableName('Personnel');
                $authAdapter->setIdentityColumn('username');
                $authAdapter->setCredentialColumn('password');
               
                // Set the input credential values to authenticate against
                $authAdapter->setIdentity($username);
                $authAdapter->setCredential($password);
               
                // do the authentication
                $auth = Zend_Auth::getInstance();
                $result = $auth->authenticate($authAdapter);
                if ($result->isValid()) {
                    // success : store database row to auth's storage system
                    // (not the password though!)
                    $data = $authAdapter->getResultRowObject(null,
'password');
                    $auth->getStorage()->write($data);
                    $this->_redirect('/');
                } else {
                    // failure: clear database row from session
                    $this->view->message = 'Login failed.';
                }
            }
        }
       
        $this->view->title = "Log in";
        $this->render();
       
    }
   
    function logoutAction()
    {
        Zend_Auth::getInstance()->clearIdentity();
        $this->_redirect('/');
    }
}


My Zend Configure file looks like this:

[general]
db.adapter = PDO_MYSQL
db.config.host = mozart.bio.ri.ccf.org
db.config.username = myusername
db.config.password = mypassword
db.config.dbname = Projects 
-- 
View this message in context: 
http://www.nabble.com/Zend_Auth-Ldap-adpator-authentication-implementation-tf4306321s16154.html#a12258348
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to