0

嗨,我编写了更改密码的代码,但它不会更改表中的密码,而是将当前密码设为 0。所以我该怎么做。谢谢

这是我的模特

function changepassword() {
$this->db->select('id');
$this->db->where('username', $this->session->userdata('username'));
$this->db->where('password', $this->input->post('OldPassword'));
$query = $this->db->get('mau_user');
if ($query->num_rows() > 0) {
    $row = $query->row();
    if ($row->id === $this->session->userdata('id')) {
        $data = array(
            'password' => $this->input->post('password')
        );
        $this->db->where('username', $this->session->userdata('username'));
        $this->db->where('password', $this->input->post('OldPassword'));
        if ($this->db->update('mau_user', $data)) {
            return "Password Changed Successfully";
4

2 回答 2

0

在控制器中

function edit_password()
{
    $uderid = $this->session->userdata('user_id');
    // update data

    if($_POST)
    {
        if($this->input->post('old_password')!=''){
            $this->form_validation->set_rules('old_password','Old password',  'trim|required|xss_clean|addslashes|encode_php_tags |callback_oldpass_check');            
            $this->form_validation->set_rules('new_password','New password', 'trim|required|xss_clean|addslashes|encode_php_tags|min_length['.PASS_MIN_LEN.']|md5');
            $this->form_validation->set_rules('conf_password', 'Confirm password', 'trim|required|xss_clean|addslashes|encode_php_tags|min_length['.PASS_MIN_LEN.']|matches[new_password]|md5');

            if($this->form_validation->run() == TRUE) 
            {       
                $data =array( 'password' => $this->input->post('conf_password'));                   
                $this->main->update('users','user_id',$uderid,$data);

                $this->change_password('Password updated successfully');                      
            }
            else{
                $this->change_password();
                }       
            }

        else{
            redirect(base_url().'user' , '301');
        }
    }       

}

 function oldpass_check($oldpass)
 {  
    $user_id = $this->session->userdata('user_id');
    $result = $this->main->check_oldpassword($oldpass,$user_id);       
        if($result ==0)
            {
                $this->form_validation->set_message('oldpass_check', "%s doesn't match.");
                return FALSE ;  

            }
         else
            {
                return TRUE ;

            }             
}

模型

function check_oldpassword($oldpass,$user_id)
{
    $this->db->where('user_id', $user_id);
    $this->db->where('password', md5($oldpass));        
    $query = $this->db->get('users'); //data table
    return $query->num_rows(); 
}
于 2014-01-23T10:18:47.753 回答
0

如果在数据库中,字段密码设置为整数,默认值为 0,因此您尝试更新的值可能无效,您应该打印 SQL 并从那里开始调试...。

于 2013-01-29T11:52:31.360 回答