2016-06-02 5 views
-1

안녕하세요 사용자 제어판의 비밀번호 변경 기능을 만들려고합니다. 수정하려고 시도했지만 뭔가 문제가 있습니다. 여기 Codeigniter 사용자 비밀번호 변경

모델 부

public function checkOldPass($old_password){ 
$this->db->where('username', $this->session->userdata('username')); 
$query = $this->db->get('users'); 
$row = $query->row(); 
echo "Old Password : ".$this->hash_password($old_password)."<br>"; 
echo "From DB : ".$row->password."<br>"; 
die; 

if($query->num_rows > 0){ 
    $row = $query->row(); 
    if($old_password == $row->password){ 
    return true; 
    }else{ 
    return false; 
    } 
} 

}

public function saveNewPass($new_password_confirm){ 
$array = array(
     'password'=>$this->hash_password($new_password_confirm) 
     ); 
$this->db->where('username', $this->session->userdata('username')); 
$query = $this->db->update('users'); 
if($query){ 
    return true; 
}else{ 
    return false; 
} 
} 

컨트롤러 부 여기

public function ucp_change_pass() { 

    $data2['title'] = "Change Password"; 
    $data = new stdClass(); 
    $this->form_validation->set_rules('old_password', 'Old Password', 'trim|required|min_length[4]'); 
    $this->form_validation->set_rules('new_password', 'New Password', 'trim|required|min_length[4]'); 
    $this->form_validation->set_rules('new_password_confirm', 'Old Password', 'trim|required|min_length[4]|matches[new_password]'); 
    if ($this->form_validation->run() === false) { 
    $this->load->view('header', $data2); 
    $this->load->view('ucp/ucp_menu'); 
    $this->load->view('ucp/ucp_change_pass', $data); 
    $this->load->view('footer'); 


     } else {  
    $old_password = $this->input->post('old_password'); 
    $new_password_confirm = $this->input->post('new_password_confirm'); 
    $query = $this->Home_model->checkOldPass($old_password); 
    if($query){ 
    $query = $this->Home_model->saveNewPass($new_password_confirm); 
    if($query){ 
     redirect('./ucp_change_pass_success'); 
    }else{ 
     redirect('./ucp_change_pass'); 
    } 
    } 

} 

} 

이다 이것은 뷰

<?php defined('BASEPATH') OR exit('No direct script access allowed'); ?> 
<?php 
if (isset($_SESSION['logged_in']) != TRUE) { 
echo redirect('/login'); 
} 
?> 
인 0
<div class="col-md-9"> 
<div class="list-group"> 
<div class="list-group-item ucp-nav-bar">User Control Panel</div> 
<div class="list-group-item"> 


  <?= form_open() ?> 



      <div class="form-group"> 
       <label for="name">Old Password</label> 
       <input type="password" class="form-control" id="old_password" name="old_password" placeholder="Enter your current password"> 

      </div> 
      <div class="form-group"> 
       <label for="email">New Password</label> 
       <input type="password" class="form-control" id="new_password" name="new_password" placeholder="Enter a new password"> 

      </div> 
      <div class="form-group"> 
       <label for="message">New Password Confrim</label> 
       <input type="password" class="form-control" id="new_password_confirm" name="new_password_confirm" placeholder="Re-enter the new password for confirmation"> 

      </div> 

      <div class="form-group"> 
       <input type="submit" class="btn btn-success" value="Change  Password"> 
      </div> 
     </form> 

오전 데 문제는 내가 일을 제출할 때 hash_password로 암호화 된 이전 암호가 데이터베이스의 암호와 동일하지 않습니다. 데이터베이스의 암호가 hash_password로 암호화되었습니다.

모델 당신은 당신의 컨트롤러하여 $ OLD_PASSWORD를 해독 할 필요가

답변

0

에서 hash_password을위한 기능입니다. 이런 식으로 컨트롤러의 다른 부분을 변경하십시오.

$old_password = $this->input->post('old_password'); 
$encrypted_old_password=password_hash($old_password) 
$new_password_confirm = $this->input->post('new_password_confirm'); 
$query = $this->Home_model->checkOldPass($encrypted_old_password); 

이전 암호를 암호화 한 다음 모델에 전달해야합니다.

+0

이전 암호 encription이 모델에서 수행됩니다. "Old Password :". $ this-> hash_password ($ old_password). "
"; /////// 또한 hash_password 함수는이 개인 함수입니다. hash_password ($ password) { \t \t \t \t return password_hash ($ password, PASSWORD_BCRYPT); \t \t \t} – rooger

관련 문제