forget password

 step1 :

view page :

 <a href="<?php echo base_url('login/forgetpassword') ?>" > Forget password ?</a>

step 2: 

controller

    public function forgetpassword(){
        $data = array();
        $this->load->view('forget_password_view', $data);
    }

step:3 

forget_password_view

        <form action="<?php echo base_url();?>login/emailcheck" method="post">
            <div  style="background: url('<?php echo base_url().'src/'; ?>images/login-bg.png');background-size: 100%;background-repeat: no-repeat;padding: 30px 40px;">

                <div class="form-group">
                    <input class="form-control form-control-solid" type="email"  
                        placeholder="Enter Email..." name="email" id="email" required="required">
                </div>
                <div class="form-group">
                    <input class="form-control form-control-solid placeholder-no-fix" type="submit" value="submit">
                </div>
            </div>
        </form>

step:4

controller

  public function emailcheck()
    {
         $email = $this->input->post('email');
         $findemail = $this->Index_model->ForgotPassword($email);  
          if($findemail){
           $this->Index_model->sendpassword($findemail);        
            }else{
           $this->session->set_flashdata('msg',' Email not found!');
           redirect(base_url().'login','refresh');
       }
    }

step:5

model -password check

    public function ForgotPassword($email)
    {
           $this->db->select('user_email');
           $this->db->from('users');
           $this->db->where('user_email', $email);
           $query=$this->db->get();
           return $query->row_array();
    }

step:6

model -  

public function sendpassword($data)
    {
        $email = $data['user_email'];
        $query1=$this->db->query("SELECT *  from users where user_email = '".$email."' ");
        $row=$query1->result_array();
        if ($query1->num_rows()>0)      
        {
            // echo "<pre>";
            // print_r($query1);
            // die;
            $passwordplain = "";
            $passwordplain  = rand(9999999,99999999);
            $newpass['user_password'] = $passwordplain;
            $this->db->where('user_email', $email);
            $this->db->update('users', $newpass);

            $mail_message='Dear '.$row[0]['user_fullname'].','. "\r\n";
            $mail_message.='Thanks for contacting regarding to forgot password,<br> Your <b>Password</b> is <b>'.$passwordplain.'</b>'."\r\n";
            $mail_message.='<br>Please Update your password.';
            $mail_message.='<br>Thanks & Regards';
            $mail_message.='<br>Rythom Blood Bank';    
           
            $config = array();
            $config['protocol'] = "smtp";
            $config['smtp_host'] = "ssl://smtp.googlemail.com";
            $config['smtp_port'] = "465";
            $config['smtp_user'] = "test@gmail.com";
            $config['smtp_pass'] = "12232";
            $config['mailtype'] = "html";
            $config['charset'] = "utf-8";
            $config['newline'] = "\r\n";
            $config['wordwrap'] = TRUE;
            $this->load->library('email');
            $this->email->initialize($config);      
                if ($email == NULL)
                    $email = 'test@gmail.com';
                $this->email->from($email);
                $this->email->to($row[0]['user_email']);
                $this->email->subject('Password Change');

                $this->email->message($mail_message);
               
                // Send email
                if ($this->email->send()) {
                    redirect(base_url().'login','refresh');
                    //echo 'Email successfully sent, please check.';
                } else {
                    $data = $this->email->print_debugger();
                    print_r($data);
                    exit();
                }
        }
    }

step:7

Comments

Popular posts from this blog

date wise search codeigniter

all customer due sql query