title: custom finder not working in CakePHP 3
body: <p>I'm working on CakePHP 3.3. I want user to login using either <strong>email</strong> or <strong>mobile number</strong> along with <strong>password</strong>.</p>
  
  <p>I have users table with <code>email, mobile, password, etc</code> fields.</p>
  
  <p>According to CakePHP <a href="https://book.cakephp.org/3.0/en/controllers/components/authentication.html#customizing-find-query" rel="nofollow noreferrer">doc</a>, I'm using custom finder <code>auth</code> to login.</p>
  
  <p><strong><code>Auth</code> component in <code>AppController.php</code></strong></p>
  
  <pre><code>    $this-&gt;loadComponent('Auth', [
          'loginRedirect' =&gt; [
              'controller' =&gt; 'Dashboard',
              'action' =&gt; 'index'
          ],
          'logoutRedirect' =&gt; [
              'controller' =&gt; 'Pages',
              'action' =&gt; 'home'
          ],
          'authenticate' =&gt; [
              'Form' =&gt; [
                  'finder' =&gt; 'auth'
              ]
          ]
      ]);
  </code></pre>
  
  <p><strong>and <code>findAuth()</code> action in <code>UsersTable.php</code></strong></p>
  
  <pre><code>public function findAuth(Query $query, array $options)
  {
      $query
          -&gt;select(['id', 'email', 'mobile', 'password'])
          -&gt;where(['Users.email' =&gt; $options['login']])
          -&gt;orWhere(['Users.mobile' =&gt; $options['login']]);
  
      return $query;
  }
  </code></pre>
  
  <p><strong>and login() action in <code>UsersController.php</code></strong> </p>
  
  <pre><code>public function login()
  {
      if ($this-&gt;request-&gt;is('post')) {
          $user = $this-&gt;Auth-&gt;identify();
          if ($user) {
              $this-&gt;Auth-&gt;setUser($user);
              return $this-&gt;redirect($this-&gt;Auth-&gt;redirectUrl());
          }
          $this-&gt;Flash-&gt;registerError(__('Invalid Credentials, try again'), ['key' =&gt; 'registration']);
      }
  }
  </code></pre>
  
  <p><strong><code>login.ctp</code> view contains</strong></p>
  
  <pre><code>&lt;?php
     echo $this-&gt;Form-&gt;create();
     echo $this-&gt;Form-&gt;input('login');
     echo $this-&gt;Form-&gt;input('password');
     echo $this-&gt;Form-&gt;submit();
     echo $this-&gt;Form-&gt;end();
  ?&gt;
  </code></pre>
  
  <p>But this is not working and prints <strong><code>Invalid Credentials, try again</code></strong></p>
  
  <blockquote>
    <p>Update 2</p>
  </blockquote>
  
  <p>Added a blank column <code>username</code> to <code>users</code> table.</p>
  
  <p><strong>login.ctp</strong></p>
  
  <pre><code>&lt;?php
     echo $this-&gt;Form-&gt;create();
     echo $this-&gt;Form-&gt;input('username');
     echo $this-&gt;Form-&gt;input('password');
     echo $this-&gt;Form-&gt;submit();
     echo $this-&gt;Form-&gt;end();
  ?&gt;
  </code></pre>
  
  <p><strong>AppController.php:authComponent</strong></p>
  
  <p>same as above</p>
  
  <p><strong>findAuth()</strong></p>
  
  <pre><code>public function findAuth(Query $query, array $options)
  {
      $query
          -&gt;orWhere(['Users.email' =&gt; $options['username']])
          -&gt;orWhere(['Users.mobile' =&gt; $options['username']]);
  
      return $query;
  }
  </code></pre>
  
  <p><strong>Now it's working. But why force to use <code>username</code> column even if not needed in application.</strong></p>