Search code examples
zend-frameworkpostgresqlauthenticationzend-auth

How to make Zend_Auth case insensitive to username?


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.


Solution

  • 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