所有用户# 39;数据库密码不定时自动修改


All users' password automatically changed in database time to time

我正在使用codeigniter php框架。我的问题是,所有的用户的密码在数据库中自动得到更改的时候,请帮助。

这是我的重置码

    function reset_now($key){
        //key of fourth segment is saved on cookie
$key = $this->uri->segment(4);

        //start validation
        $this->form_validation->set_rules('password','Password','xss_clean|required|alpha_numeric|min_length[6]|max_length[20]|matches[password_conf]|sha1');
        $this->form_validation->set_rules('password_conf','Password Confirmation','xss_clean|required|alpha_numeric|matches[password]|sha1');
        if($this->form_validation->run() == FALSE){

            $this->load->view('account/reset_password');

        }else{

            $this->db->set('password', $this->_salt.$this->input->post('password'));
                    $this->db->where('lostkey', $_POST['lostkey']);
            $this->db->update('users');
            $this->session->set_flashdata('message','Password changed, please login with new password');

                    redirect('account/login');
        //$this->load->view('account/reset_password_complete');
    }
}

您可能忘记了密码更新sql中的where条件。请重新检查您的sql。密码不会自动更改。当有人试图更改密码时,可能会触发。


按提供的代码更新

你的update where condition是,$this->db->where('lostkey', $_POST['lostkey']);

where子句应该使用用户id(数据库中用户的主键)而不是使用lostkey(这不是什么意思,有可能有多个行具有相同的lostkey)。

所以,你的where子句必须像

$this->db->where('id', $user_id)