I'm having a problem with my validation. I'm using Codeigniter's Native Form Validation.
I'm doing a user update feature but, I fail to validate the oldpassword. Whenever I type correct value of oldpassword, it fails to submit. But when I type it incorrectly, it went good.
Well, this is a part of the controller
$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');
and this is the password checker function
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;
}
}
and this is the model of the checker
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;
}
}