azz0r
azz0r

Reputation: 3311

Zend_Auth multiple credentials?

Login Form:

    $authAdapter    = Zend_Registry::get('authAdapter');
    $authAdapter
  ->setIdentity($formData['email'])
  ->setCredential($password)
  ->setCredential(1);

Bootstrap:

    protected function _initAuth(){
    $this->bootstrap('db');
    $this->bootstrap('session');

    $db             = $this->getPluginResource('db')->getDbAdapter();
    $auth           = Zend_Auth::getInstance();
    $authAdapter    = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', 'enabled');

    Zend_Registry::set('authAdapter', $authAdapter);
    return $authAdapter;
}

Obviously since adding 'enabled' its stopped working, if I remove:

->setCredential(1);

and 'enabled' from there:

($db, 'User', 'email', 'password', 'enabled');

it works just fine...

I would like to only enable users who have an enabled account to login though.

EDIT:

        $authAdapter    = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', '(?) AND `enabled` = 1');

works :)

Upvotes: 1

Views: 1317

Answers (3)

Shilbhushan
Shilbhushan

Reputation: 1

You can set additional conditions in the auth adapter i.e.

$select = $authAdapter->getDbSelect();
$select->where("isActive = ?","Active");

Upvotes: 0

Kasia Gogolek
Kasia Gogolek

Reputation: 3414

please try:

$authAdapter    = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', 'AND enabled      > 1');

and remove:

->setCredential(1);

Upvotes: 1

Gabriel Solomon
Gabriel Solomon

Reputation: 30095

You need to modify your adapter like so:

$authAdapter = new Zend_Auth_Adapter_DbTable(
    $db,
    'user',
    'email',
    'password',
    'MD5(?) AND `enabled` = "true"');

Upvotes: 1

Related Questions