【发布时间】:2016-01-25 06:59:21
【问题描述】:
我的验证有问题。我正在使用 Codeigniter 的原生表单验证。
我正在执行用户更新功能,但是我无法验证 oldpassword。每当我输入正确的oldpassword 值时,它都无法提交。但是当我输入错误时,它很好。
嗯,这是控制器的一部分
$this->form_validation->set_rules('oldpassword', 'Old Password', 'required|callback_password_check');
$this->form_validation->set_rules('password', 'New Password', 'required|matches[confirmpassword]');
$this->form_validation->set_rules('confirmpassword', 'New Password Confirmation', 'required');
这是密码检查功能
function password_check($str){
$result = $this->create_model->check_password($str);
if($result)
{
$this->form_validation->set_message('password_check', 'Password does not match!');
return false;
}
else{
return true;
}
}
这是检查器的模型
function check_password($str){
$this->db->select('*');
$this->db->from('users');
$this->db->where('id', $this->input->post('id'));
$this->db->limit(1);
$query = $this->db-> get();
if($query->num_rows() == 1) {
//GETS PASSWORD FOR HASHING
foreach($query->result() as $rows) {
$hash = $rows->password;
}
//VERIFY PASSWORD
if (password_verify($str, $hash)) {
$this->session->set_flashdata('success', 'Success! You have changed the password'); //DONT MIND THIS, ITS A TEST
return true;
} else {
$this->session->set_flashdata('error', 'Old Password is incorrect'); //DONT MIND THIS, ITS A TEST
return false;
}
} else {
return false;
}
}
【问题讨论】:
标签: php codeigniter