2

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.

Alex N.
  • 14,805
  • 10
  • 46
  • 54
  • Hi @Alex N. i face same issue can you see my question https://stackoverflow.com/questions/47300930/how-to-make-username-case-insensitive-in-zf2 as you already face this issue – Muhammad Arif Nov 17 '17 at 05:17

2 Answers2

3

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

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • 1
    +1. And it would be nice to wrap this into a custom auth adapter extending `Zend_Auth_Adapter_DbTable` with a simpler constructor `public function __construct($dbAdapter)` and an overridden `setIdentity()` method. See http://pastebin.com/a6KnhKw8. – David Weinraub Jan 22 '12 at 06:23
  • Hi @David i face same problem can you see my question https://stackoverflow.com/questions/47300930/how-to-make-username-case-insensitive-in-zf2 any help appreciable – Muhammad Arif Nov 17 '17 at 05:13
0

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.

drew010
  • 68,777
  • 11
  • 134
  • 162
  • Hi @drew010 can you see my question https://stackoverflow.com/questions/47300930/how-to-make-username-case-insensitive-in-zf2 any help appreciable – Muhammad Arif Nov 17 '17 at 04:49