title: How to reset Password Using PHP Codeigniter
body: <p>Am working on a Password reset system whereby the user who forgot his password can request for password reset link by submitting his email used in registration. I successfully create the email, it sent the link and I test the link by clicking on it. The link went through and load the reset page but my problem is how to make the system recognise the user who click through and get all the details including Name, Token, email with which the system will confirm that the user is the user who requested the link.</p>
  
  <p>The following is what I have done so far:</p>
  
  <p>Controller</p>
  
  <pre><code>    public function preset(){
          $data['success']='';
          $data['error']='';
          include_once ('query/user_query.php');
  
          $this-&gt;form_validation-&gt;set_rules('email','Email','trim|required|valid_email');
           $this-&gt;form_validation-&gt;set_error_delimiters("&lt;div class='alert alert-warning'&gt;&lt;span type='button' class='close' data-dismiss='alert'&gt;&amp;times&lt;/span&gt;","&lt;/div&gt;");
  
      if($this-&gt;form_validation-&gt;run() == false){
  
          $this-&gt;load-&gt;view('passwordrecovery.php', $data);
      }
      else{
          $eMail = $this-&gt;input-&gt;post('email');
           $this-&gt;db-&gt;where("email = '$eMail'");
          $this-&gt;db-&gt;from("useraccount");
          $countResult = $this-&gt;db-&gt;count_all_results();
  
  
          if($countResult &gt;=1){
             // $data['firstName'] = '';
            //  $data['lastName'] = '';
              $this-&gt;db-&gt;where("email = '$eMail'");
              $getUserData =$this-&gt;db-&gt;get("useraccount")-&gt;result();
               foreach($getUserData as $userD){
  
               $data['firstName'] = $userD-&gt;firstname;
               $data['lastName'] = $userD-&gt;lastname;
               }
              $sender_email = 'xxx@gmail.com';
              $user_password = 'xxxxxx';
              $token = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 50);
              $subject = 'Password Reset';
              $message = '';
              $message .= "&lt;h2&gt;You are receiving this message in response to your request for password reset&lt;/h2&gt;"
                      . "&lt;p&gt;Follow this link to reset your password &lt;a href='".site_url()."/authenticate/resetpassword/.$token' &gt;Reset Password&lt;/a&gt; &lt;/p&gt;"
                      . "&lt;p&gt;If You did not make this request kindly ignore!&lt;/p&gt;"
                      . "&lt;P class='pj'&gt;&lt;h2&gt;Kind Regard: Votemate&lt;/h2&gt;&lt;/p&gt;"
                      . "&lt;style&gt;"
                      . ".pj{"
                      . "color:green;"
                      . "}"
                      . "&lt;/style&gt;"
                      . "";
              // Configure email library
   $config['protocol'] = 'smtp';
   $config['smtp_host'] = 'ssl://smtp.googlemail.com';
   $config['smtp_port'] = 465;
   $config['smtp_user'] = $sender_email;
   $config['smtp_pass'] = $user_password;
   $config['mailtype'] = 'html';
  
   // Load email library and passing configured values to email library
   $this-&gt;load-&gt;library('email', $config);
   //$this-&gt;email-&gt;set_newline("rn");
   $this-&gt;email-&gt;set_mailtype("html");
  
   // Sender email address
   $this-&gt;email-&gt;from($sender_email);
   // Receiver email address
   $this-&gt;email-&gt;to($eMail);
  // Subject of email
  $this-&gt;email-&gt;subject($subject);
  // Message in email
  $this-&gt;email-&gt;message($message);
  
  if ($this-&gt;email-&gt;send()) {
  
  $eMail = $this-&gt;input-&gt;post('email');
  $ipadd = $this-&gt;input-&gt;ip_address();
  $insert = array(
    'email' =&gt; $eMail,
      'ipaddress' =&gt; $ipadd,
      'token' =&gt; $token
   );
  
   $this-&gt;db-&gt;insert('passwordreset', $insert);
   $mail = $this-&gt;session-&gt;set_userdata('email');
   $data['success'] = 'Email Successfully Send !';
   $this-&gt;load-&gt;view('linksent.php', $data);
   } else {
   $data['error'] =  '&lt;p class="error_msg"&gt;Invalid Gmail Account or Password ! 
    &lt;/p&gt;';
   }
   $this-&gt;load-&gt;view('passwordrecovery.php', $data);
    }
  
  
          if($countResult &lt;= 0){
  
              //user already registered
  
              $data['error'] = "&lt;div class='alert alert-warning'&gt; Invalid 
      email address&lt;span type='button' class='close' data- 
      dismiss='alert'&gt;&amp;times&lt;/span&gt;&lt;/div&gt;";
  
              $this-&gt;load-&gt;view('passwordrecovery.php',$data);
  
          }
  
          }
  
  
           }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>     &lt;div&gt;
                  &lt;h1&gt;Password Recovery&lt;/h1&gt;
                  &lt;h3&gt;Enter your email to receive the password reset link in 
         your Inbox&lt;/h3&gt;
                  &lt;br/&gt;
  
                  &lt;?php echo form_open('authenticate/preset');?&gt;
                  &lt;?php echo $error;?&gt;
                  &lt;div class="form-group"&gt;
                      &lt;input type="text" name="email" required="required"&gt;
  
                  &lt;/div&gt;
                  &lt;div class="form-group"&gt;
                      &lt;input type="submit" value="Send" class="btn-success 
        btn" &gt;
                  &lt;/div&gt;
                  &lt;?php echo form_close()?&gt;
       &lt;br/&gt;&lt;br/&gt;&lt;br/&gt;
  
  
              &lt;/div&gt;
  </code></pre>
  
  <p>Database: The following is database where I store the info:</p>
  
  <pre><code>   CREATE TABLE `passwordreset` (
     `resetid` int(11) NOT NULL,
     `email` varchar(150) NOT NULL,
     `ipaddress` varchar(25) NOT NULL,
     `token` varchar(512) NOT NULL
    ) ENGINE
  </code></pre>
  
  <p>The help I need is how to get the details (Name, email, token) of the user who click the link from his email and use it to validate and also use it to update his password. Thanks</p>