On Wed, Jun 23, 2010 at 1:21 PM, robert mena <[email protected]> wrote:
> Hi,
> I am using Zend_Auth to authenticate my users in an application.  I was
> requested to provide a 'god' mode where the admin will enter the username
> and a special password and  login as that user.
> No matter how I dislike the idea I have to implement it.  So In my view if
> the password is the special one I'd have to 'inject' the credentials to the
> zend_auth so in further requests (in the controllers that require the login
> user) everything will continue without a problem.
> Question:
> - How can I do it?
> Regards.

It is pretty easy to extend whichever regular authentication adapter
you are using for regular log-ins. Just override the authenticate()
method with something similar to this:

<?php
// Assuming you are using the DbTable adapter.
class My_New_Auth_Adapter extends Zend_Auth_Adapter_DbTable
{

    public function authenticate()
    {

        if ('supreme_username' === $this->_identity) {
            if ('supreme_password' === $this->_credential) {
                return new Zend_Auth_Result(
                    Zend_Auth_Result::SUCCESS,
                    'supreme_user',
                    array('authentication successful'));
            } else {
                return new Zend_Auth_Result(
                    Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID,
                    'supreme_user',
                    array('invalid credentials'));
            }
        } else {
            return parent::authenticate();
        }
    }

}
?>

Andrew

Reply via email to