Today, We want to share with you forgot password in codeigniter.In this post we will show you forgot password using otp in php, hear for codeigniter login and registration with forgot password we will give you demo and example for implement.In this post, we will learn about PHP Change Password Script Using Mysqli with an example.
forgot password with generated code in codeigniter
Forms.php (Controller)
load->database(); $this->load->library('session'); /*load Model*/ $this->load->helper('url'); $this->load->model('Hello_model'); } public function forgot_pass() { if($this->input->post('forgot_pass')) { $email=$this->input->post('email'); $que=$this->db->query("select pass,email from member_login where email='$email'"); $row=$que->row(); $member_email=$row->email; if((!strcmp($email, $member_email))){ $pass=$row->pass; /*Mail Code*/ $to = $member_email; $subject = "Password"; $txt = "Your password is $pass ."; $headers = "From: [email protected]" . "\r\n" . "CC: [email protected]"; mail($to,$subject,$txt,$headers); } else{ $data['error']=" Invalid Email ID ! "; } } $this->load->view('forgot_pass',@$data); } } ?>
forgot_pass.php (View)
Login Form Forgot Password
Run the program on your browser with URL:
http://localhost/codeIgniter/index.php/Crud/storememberinfo
Forgot password with generated code in CodeIgniter
Html view
public function ForgotPassword() { $email = $this->input->post('email'); $findemail = $this->MY_model->ForgotPassword($email); if ($findemail) { $this->MY_model->sendpassword($findemail); } else { echo ""; redirect(base_url() . 'MY_controller/index', 'refresh'); } }
This controller function
public function ForgotPassword($email) { $this->db->select('email'); $this->db->from('table'); $this->db->where('email', $email); $query=$this->db->get(); return $query->row_array(); }
This model function
public function sendpassword($data) { $email = $data['email']; $query1=$this->db->query("SELECT * from tablename where email = '".$email."' "); $row=$query1->result_array(); if ($query1->num_rows()>0) { $passwordplain = ""; $passwordplain = rand(999999999,9999999999); $newpass['password'] = md5($passwordplain); $this->db->where('email', $email); $this->db->update('employer_registration', $newpass); $mail_message='Dear '.$row[0]['name'].','. "\r\n"; $mail_message.='Thanks for contacting regarding to forgot password,
Your Password is '.$passwordplain.''."\r\n"; $mail_message.='
Please Update your password.'; $mail_message.='
Thanks & Regards'; $mail_message.='
Your company name'; require 'PHPMailerAutoload.php'; require 'class.phpmailer.php'; $mail = new PHPMailer; $mail->IsSendmail(); $mail->isSMTP(); $mail->SMTPAuth = true; $mail->Host = "hostname"; $subject = 'Testing Email'; $mail->AddAddress($email); $mail->IsMail(); $mail->From = 'admin@***.com'; $mail->FromName = 'admin'; $mail->IsHTML(true); $mail->Subject = $subject; $mail->Body = $mail_message; $mail->Send(); if (!$mail->send()) { echo ""; } else { echo ""; } redirect(base_url().'Jobseeker/index','refresh'); } else { echo ""; redirect(base_url().'Jobseeker/index','refresh'); } }
I hope you get an idea about forgot password gmail in codeigniter.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.