2017-07-27 11 views
-1

ログインユーザーのパスワードを変更する方法はありますか?ログインしたユーザーのパスワードを変更したいのですが、私が作成したコードはユーザーID番号1のユーザーパスワードを変更するだけです。ログインしたユーザーは変更されません。そう考えていますか?ログインユーザーのパスワードを変更する方法

これは私のコントローラである:

public function update(){ 
$this->form_validation->set_rules('password', 'Current Password', 'required|alpha_numeric|min_length[6]|max_length[20]'); 
$this->form_validation->set_rules('newpass', 'New Password', 'required|alpha_numeric|min_length[6]|max_length[20]'); 
$this->form_validation->set_rules('confpassword', 'Confirm Password', 'required|alpha_numeric|min_length[6]|max_length[20]'); 

if($this->form_validation->run()){ 
    $cur_password = $this->input->post('password'); 
    $new_password = $this->input->post('newpass'); 
    $conf_password = $this->input->post('confpassword'); 
    $this->load->model('queries'); 
    $userid = '1'; 
    $passwd = $this->queries->getCurrPassword($userid); 
    if($passwd->password == $cur_password){ 
     if($new_password == $conf_password){ 
      if($this->queries->updatePassword($new_password, $userid)){ 
       echo 'Password updated successfully'; 
      } 
      else{ 
       echo 'Failed to update password'; 
      } 
     } 
     else{ 
      echo 'New password & Confirm password is not matching'; 
     } 
    } 
    else{ 
     echo'Sorry! Current password is not matching'; 
    } 
}else{ 
echo validation_errors(); 
} 

これは私のモデルである:誰かがログインすると

public function getCurrPassword($userid){ 
$query = $this->db->where(['id'=>$userid]) 
       ->get('users'); 
if($query->num_rows() > 0){ 
    return $query->row(); 
} } 
public function updatePassword($new_password, $userid){ 
$data = array(
    'password'=> $new_password 
); 
    return $this->db->where('id', $userid) 
        ->update('users', $data); } 
+1

これはどのフレームワークですか?単純にパスワードを変更するための複雑なプログラミングのように思える。 –

+0

これはあなたが$ userid = '1'を持っているからです。あなたのifブロックに。 – Vagabond

+0

codeigniter @EdwardB。 –

答えて

0

することは、あなたは、ユーザ名、IDとして、ユーザー情報を保存するために$_SESSIONを設定する必要があり、電子メール、...あなたが必要なときに使用する。その後、$_SESSION['session_name']['id']を確認してユーザーのパスワードを変更することができます。 $_SESSIONは重要であり、ユーザーがログインするときに設定する必要があります。

関連する問題