How to make Zend_Auth case insensitive to username?

651 views Asked by At

Is there a way to make Zend_Auth to accept case-insensetive identities(i.e. usernames)? Zend_Auth seems to provide a way to add special treatment to a credential field, but not to identity field.

PS: I am using Zend_Auth_Adapter_DbTable that points to Postgres table.

2

There are 2 answers

2
Sudhir Bastakoti On BEST ANSWER

Something like this should work:


$authAdapter = new Zend_Auth_Adapter_DbTable(
       $dbAdapter,
       'usertable',
       new Zend_Db_Expr('LOWER(username)'),
       'password'
);

$authAdapter
   ->setIdentity(strtolower($this->_getParam('username'))
   ->setCredential($this->_getParam('password')); 

And be sure to use one of the *_ci collations in your database for username field (ci = case-insensitive). Hope it helps

1
drew010 On

You could alter your table so the username column is of type citext so it is case-insensitive and you still get the benefit of using the index.