1

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 :)

azz0r
  • 3,283
  • 7
  • 42
  • 85

3 Answers3

1

You need to modify your adapter like so:

$authAdapter = new Zend_Auth_Adapter_DbTable(
    $db,
    'user',
    'email',
    'password',
    'MD5(?) AND `enabled` = "true"');
Gabriel Solomon
  • 29,065
  • 15
  • 57
  • 79
1

please try:

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

and remove:

->setCredential(1);
Kasia Gogolek
  • 3,374
  • 4
  • 33
  • 50
  • This didn't work. Infact I changed 'AND `enabled` = "1"' to 'AND jimmy = blah' and it still logged in, leading me to believe its ignored that last field! – azz0r Mar 18 '10 at 11:45
  • See first post: it was: $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password', '(?) AND `enabled` = 1'); – azz0r Mar 18 '10 at 11:54
  • how about this: $authAdapter = new Zend_Auth_Adapter_DbTable($db, 'User', 'email', 'password'); and then $select = $authAdapter->getDbSelect(); $select->where('enabled = 1'); $authAdapter->authenticate(); which ZF version are you using? thx – Kasia Gogolek Mar 18 '10 at 11:55
  • isn't this solution to this problem a bit hacky? – Dario Russo Aug 23 '11 at 20:23
0

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

$select = $authAdapter->getDbSelect();
$select->where("isActive = ?","Active");
Jonathan de M.
  • 9,721
  • 8
  • 47
  • 72