2016-12-19 18 views
-1

我生成了随机代码,但无法使用数据库表中的密码进行更新。使用CodeIgniter中的生成代码来忘记密码

下面是我忘记密码控制器代码:

public function forgot(){ 
    if($this->input->post('submit')) { 
     $email = $this->input->post('email'); 
     $qry['email'] = $this->Employer_model->select($email); 
     $email1 = $qry['email']->email; 

     if($email1 == $email) { 
      $code1 = rand(); 
      $code = md5($code1); 
      $employer_id = $GLOBALS['employer_id']; 
      $qry1 = $this->Employer_model->insertpwd($code, $employer_id); 

      if($qry1) { 
       echo "<script>alert(' your new password is $code1!')</script>"; 
      } 
     } 
    } 

    $this->load->view('employer/forgot'); 
} 
+3

所以发送电子邮件,哪里是问题吗?你的问题在哪里?你找到解决方案? – kishor10d

+0

我的问题是,我不能用我的旧密码更新新生成的代码。 – Tejaswee

回答

0
<form id="resetPassword" name="resetPassword" method="post" action="<?php echo base_url();?>My_Controller/ForgotPassword" onsubmit ='return validate()'> 
        <table class="table table-bordered table-hover table-striped"> 
         <tbody> 
         <tr> 
          <td>Enter Email: </td> 
          <td> 
           <input type="email" name="email" id="email" style="width:250px" required> 
          </td> 
          <td><input type = "submit" value="submit" class="button"></td> 
         </tr> 

         </tbody>    </table></form> 

HTML视图

public function ForgotPassword() 
{ 
    $email = $this->input->post('email'); 
    $findemail = $this->MY_model->ForgotPassword($email); 
    if ($findemail) { 
     $this->MY_model->sendpassword($findemail); 
    } else { 
     echo "<script>alert(' $email not found, please enter correct email id')</script>"; 
     redirect(base_url() . 'MY_controller/index', 'refresh'); 
    } 
} 

该控制器功能

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(); 
} 

这从数据库表中选择电子邮件的借鉴作用

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,<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>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 = '[email protected]***.com'; 
     $mail->FromName = 'admin'; 
     $mail->IsHTML(true); 
     $mail->Subject = $subject; 
     $mail->Body = $mail_message; 
     $mail->Send(); 
     if (!$mail->send()) { 

      echo "<script>alert('msg','Failed to send password, please try again!')</script>"; 
     } else { 

      echo "<script>alert('msg','Password sent to your email!')</script>"; 
     } 
     redirect(base_url().'Jobseeker/index','refresh'); 
    } 
    else 
    { 

     echo "<script>alert('msg','Email not found try again!')</script>"; 
     redirect(base_url().'Jobseeker/index','refresh'); 
    } 
} 

这种模式功能创建randome密码和注册邮箱