更改密码的代码 - Codeigniter

时间:2014-07-10 04:07:29

标签: passwords

我正在测试我的代码以更改密码。 如果旧密码不匹配,则必须回显错误: '旧密码不正确'

代码很简单,但我无法指出我做错了什么,请检查

这是我的控制器:

function change_password(){
    $this->form_validation->set_rules('opassword','Old Password','trim|min_length[6]|required|xss_clean');
    $this->form_validation->set_rules('password','Password','trim|min_length[6]|xss_clean|required');
    $this->form_validation->set_rules('cpassword','Password Confirmation','trim|min_length[6]|required|matches[password]|xss_clean');

    if($this->form_validation->run()==False){

        $this->upload_profile();
    }
    else{

        $this->account_model->change_password();

    }
}

以下是我的模型代码:

function change_password(){
    $this->load->helper('security');
    $this->db->select('password');
    $query= $this->db->get_where('users',array('username'=>$this->session->userdata('username')));

    $pass = do_hash($this->input->post('opassword')).br();
    echo $pass;
    $row = $query->row();
    echo $row->password.br();

    if($pass != $row->password){
        echo 'Old Password is Incorrect';
        exit();

    }else{
        echo 'Password Matched';
    }


}

通过echo语句我可以看到旧密码是正确的。但它总是显示 - 旧密码不正确

由于

0 个答案:

没有答案