Hi,

Yes you can chain authentication.

You can try something like this:

/**
* Authenticate user
*
* @param string $login
* @param string $password
* @return boolean
*/
public function authenticate($login, $password)
{
    //Default table, test for admin_user
    $auth_adapter = new Adapter\DbTable($this->getAdapter());
    $auth_adapter->setTableName('admin_user');
    $auth_adapter->setIdentityColumn('email');
    $auth_adapter->setCredentialColumn('password');

    $auth_adapter->setIdentity($login);
    $auth_adapter->setCredential(md5($password));

    $auth = new AuthenticationService(new
Storage\Session(self::BACKEND_AUTH_NAMESPACE));
    $result = $auth->authenticate($auth_adapter);

    if($result->isValid())
    {
        //authenticate with admin user table
        $data = $auth_adapter->getResultRowObject(null, 'password');
        $this->setData((array)$data);
        $auth->getStorage()->write($this);

        return TRUE;
    }
    else
    {
        //Not working tried with user table
        $auth_adapter = new Adapter\DbTable($this->getAdapter());
        $auth_adapter->setTableName('user');
        $auth_adapter->setIdentityColumn('login');
        $auth_adapter->setCredentialColumn('password');

        $auth_adapter->setIdentity($login);
        $auth_adapter->setCredential(sha1($password));

        $auth = new AuthenticationService(new
Storage\Session(self::BACKEND_AUTH_NAMESPACE));
        $result = $auth->authenticate($auth_adapter);
        if($result->isValid())
        {
            //authenticate with user table
            $data = $auth_adapter->getResultRowObject(null, 'password');
            $this->setData((array)$data);
            $auth->getStorage()->write($this);

            return TRUE;
        }
    }

    //Auth failed
    return FALSE;
}


Regards,

2013/2/18 Ralf Eggert <r.egg...@travello.de>

> Hi,
>
> I want to migrate a old ZF1 application to ZF2. In the ZF1 application
> the user passwords are stored in a database as a MD5 hash. In the ZF2
> application I want to use Zend\Crypt\Password\Bcrypt. It is impossible
> to convert the passwords.
>
> So, I will use the following approach: If a user is logging in the first
> time in the ZF2 application he is asked to enter his old MD5 hashed
> password. Afterwards he is forced to enter a new password which is saved
> as a Bcrypt hash.
>
> Technically I am thinking about using two authentication adapters.
> Default is the Bcrypt adapter. If it fails, the MD5 adapter should be used.
>
> Is it possible to chain authentication adapters or should I write my own
> adapter which is implementing this szenario? I already have a custom
> authentication adapter for the Bcrypt authentication anyway.
>
> Thanks and regards,
>
> Ralf
>
> --
> Ralf Eggert
> Geschäftsführer
>
> Travello GmbH
> An der Eiche 15
> 25421 Pinneberg
>
> Geschäftsführer: Ralf Eggert
> Amtsgericht Pinneberg HRB 6112 PI
>
> Tel: 04101/8529401
> Fax: 04101/8529402
> E-Mail: i...@travello.de
> Web: http://www.travello.de
>
> --
> List: fw-general@lists.zend.com
> Info: http://framework.zend.com/archives
> Unsubscribe: fw-general-unsubscr...@lists.zend.com
>
>
>


-- 
Pierre Rambaud
Website: http://rambaudpierre.fr
G+: https://plus.google.com/u/0/107809758756474139920/posts
Github: https://github.com/PierreRambaud

Reply via email to