Most of the developers will look for forgot password functionality, now
I will show you to create forgot password form in 2 easy steps. For this we need to create below files.
1) Forgotpassword.php(view)
2) User.php(controller)
Now create above two files in your projects to get functionality work.

<div class="container"> <div class="row padding-top-btm"> <div class="col-md-4"> <div class="new-car-con"> <form method="post" action="doforget" role="form" > <div class="form-group"> <?php if($this->session->flashdata('message')) {?> <label><span style="color: #CC6633"><?php echo $this->session->flashdata('message');?><span></label> <?php }?> </div> <h4>Forget pasword</h4> <div class="form-group"> <label for="txtLoginid">Email Id</label> <input name="emailid" type="email" size="25" id="emailid" placeholder="Enter email" class="form-control" value="<?php echo set_value('emailid');?>" /> <span style="color:red"><?php echo form_error('emailid');?></span> </div> <button type="submit" class="btn btn-default">Submit</button> </form> </div></div> </div> </div>
Now create controller file as below.
[sociallocker id=”3592″]
<?php class User extends CI_Controller { public function __construct() { parent::__construct(); } public function display_doforget() { $data=""; $this->load->view('user/forgetpassword',$data); } public function doforget() { $this->load->helper('url'); $email= $this->input->post('emailid'); $this->load->library('form_validation'); $this->form_validation->set_rules('emailid','emailid','required|xss_clean|trim'); if ($this->form_validation->run() == FALSE) { $this->load->view('user/forgetpassword'); } else { $q = $this->db->query("select * from user where emailid='" . $email . "'"); if ($q->num_rows > 0) { $r = $q->result(); $user=$r[0]; $this->load->helper('string'); $password= random_string('alnum',6); $this->db->where('user_id', $user->user_id); $this->db->update('user',array('password'=>$password,'pass_encryption'=>MD5($password))); $this->load->library('email'); $this->email->from('[email protected]', 'sampletest'); $this->email->to($user->emailid); $this->email->subject('Password reset'); $this->email->message('You have requested the new password, Here is you new password:'. $password); $this->email->send(); $this->session->set_flashdata('message','Password has been reset and has been sent to email'); redirect('user/display_doforget'); } } } }
[/sociallocker]
jQuery For Beginners: Your Guide To Easily Learn jQuery Programming in 7 days
Thanks for reading this article.
Hi!Saritha I would be very grateful to you if you can show me how to create a blog using codeigniter where the posts are displayed in descending order of time.
usefull post boss!!