views:

208

answers:

2

Currently, I'm getting a regular DbTable Auth Adapter:

protected function _getAuthAdapter($formData)
{    
    $dbAdapter = Zend_Db_Table::getDefaultAdapter();
    $authAdapter = new Zend_Auth_Adapter_DbTable($dbAdapter);
    $authAdapter->setTableName('users')
        ->setIdentityColumn('username')
        ->setCredentialColumn('password');
    $authAdapter->setIdentity($formData['username']);
    $authAdapter->setCredential(md5($formData['password']));
    return $authAdapter;
}

But I want to check an additional column in the database. I don't know if this can be done with the adapter. How can this be done?

A: 

The included Auth Adapater Zend_Auth_Adapter_DbTable does not allow you to check an additional column. You could extend the Zend_Auth_Adapter_DbTable class and add another column. You will have to add a member variable for the value of new field $_otherFieldValue and a public function setMemberField($value). Finally, you would have to override:

protected function _authenticateCreateSelect()

Hope that helps.

Brian Fisher
+1  A: 

I use two columns for my Zend_Auth_Adapter_DbTable, and it looks like this:

$authAdapter = new Zend_Auth_Adapter_DbTable(
  Zend_Registry::get('database'),
  "user",
  "username",
  "password_hash", // column 1
  "MD5( CONCAT(?,password_salt) )" // column 2
);

When authenticating, the SQL ends up looking like this:

SELECT `user`.*, 
(CASE WHEN `password_hash` = MD5( CONCAT('password entered',password_salt) )
  THEN 1 ELSE 0 END) AS `zend_auth_credential_match`
FROM `user` WHERE (`username` = 'username entered')

So, that checks an additional column, password_salt, and for me it works well. I don't know if that helps you, as I don't know what you're trying to do.

Derek Illchuk
I don't really understand this...Can you please expand upon your answer? Specifically on the order of params and how it works.
Andrew