codeIgniter_3_1_11/login/forgotpassword
public function forgotpassword(){
if(!empty($_POST))
{
$email = $this->input->post('email');
$get = $this->db->where('email',$email);
$get = $this->db->get('user_accounts');
if($get->num_rows() > 0) {
$string = '';
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$max = strlen($characters) - 1;
for ($i = 0; $i < 8; $i++) {
$string .= $characters[mt_rand(0, $max)];
}
$hashed_password = password_hash($string, PASSWORD_DEFAULT);
$data = array(
'password' => $hashed_password,
);
$this->db->where('user_id', $get->row()->user_id);
$this->db->update('user_accounts',$data);
$data['name'] = $get->row()->account_name;
$data['password'] = $string;
$this->load->library('email');
$config['mailtype'] = 'html';
$this->email->initialize($config);
$this->email->from('testingyops@gmail.com', 'Demo Email');
$this->email->to($this->input->post('email'));
$htmlMessage = $this->load->view('email_app/forgot_password_panel', $data, true);
$this->email->subject('Forgot Password - Demo Email');
$this->email->message($htmlMessage);
@$this->email->send();
$this->session->set_flashdata('SUCCESSMSGREGISTER', 'Password successfully changed. please check your email.');
redirect ('login/forgotpassword' );
}else{
echo "ELSE-----------";
die();
$this->session->set_flashdata('Message','Email-Id does not exist');
}
}
$this->load->view('login/forgotpassword');
}
Comments
Post a Comment