title: Login in CodeIgniter with password_verify
body: <p>I'm trying to achieve to login implementation in CodeIgniter, I'm hashing password while registration like <code>password_hash($this-&gt;input-&gt;post('password'),PASSWORD_DEFAULT)</code> in my Controller and in the same Controller I'm trying to write a login method which is as followed : </p>
  
  <pre><code>public function loginValidation() {
          $this-&gt;form_validation-&gt;set_rules('email', 'Email', 'trim|required');
          $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required');
  
          if ($this-&gt;form_validation-&gt;run()) {
              // true
              $email  =   $this-&gt;input-&gt;post('email');
              $password   =   $this-&gt;input-&gt;post('password');
  
              // User Model Loaded in constructor
              if ($this-&gt;user-&gt;canLogin($email, $password)) {
                  $session_data   =   array('email' =&gt; $email );
                  $this-&gt;session-&gt;set_userdata($session_data);
                  redirect('profile/personal','Refresh');
  
              } else {
                  $this-&gt;session-&gt;set_flashdata('error', 'Invalid Username or Password');
                  //redirect('login','Refresh');
  
              }
          } else {
              // try again to login
              //redirect('login','Refresh');
          }
      }
  </code></pre>
  
  <p>My user Model function is </p>
  
  <pre><code>public function canLogin($email, $password) {
      $this-&gt;db-&gt;where('email',$email);
      $this-&gt;db-&gt;where('password',$password);
      $query  =   $this-&gt;db-&gt;get($this-&gt;tableName);
  
      if ($query-&gt;num_rows() &gt; 0) {
          return true;
      } else {
          return false;
      }
  }
  </code></pre>
  
  <p>I know I have to <code>password_verify($string,$hash)</code> at some point but I'm unable to figure out. </p>
  
  <p>How do I validate the password against email and redirect to the desired view i.e. <code>personal/profile</code> and I'm making request via AJAX call.</p>