title: Codeigniter 4 allow user to login using either username or email
body: <p>Currently I have a login feature and I have only set user can login using username. How do I make it for user to login either using username or email and check with my database if username exist when users login with their username and if email exist when users login with their email? Below is my current code:</p>
  <p>Controller</p>
  <pre><code>public function login()
      {
          $data = [];
          helper(['form']);
          
          $validation =  \Config\Services::validation();
          
          if($this-&gt;request-&gt;getMethod() == 'post'){
              //validations
              $rules = [
                  'username' =&gt; 'required',
                  'password' =&gt; 'required|validateUser[username, password]'
              ];
              
              $errors = [
                  'password' =&gt; [
                      'validateUser' =&gt; 'Username or Password don\'t match'
                  ]
              ];
              
              if(!$this-&gt;validate($rules, $errors)){
                  $data['validation'] = $this-&gt;validator;
              }else{
                  $model = new AccountModel();
                  
                  $user = $model-&gt;where('username', $this-&gt;request-&gt;getVar('username'))
                                -&gt;first();
                                
                  $this-&gt;setUserSession($user);
                  return redirect()-&gt;to('/account/profile');
                  
              }
              
          }
          
          echo view('templates/header', $data);
          echo view('account/login');
          echo view('templates/footer');
      }
  </code></pre>
  <p>My validation rules</p>
  <pre><code>&lt;?php
  
  namespace App\Validation;
  
  use App\Models\AccountModel;
  
  class UserRules
  {
      
      public function validateUser(string $str, string $fields, array $data)
      {
          $model = new AccountModel();
          $user = $model-&gt;where('username', $data['username'])
                        -&gt;first();
                        
          if(!$user)
              return false;
          
          return password_verify($data['password'], $user['password']);
      }
  }
  
  ?&gt;
  </code></pre>
  <p>Thanks in advance guys!</p>