CodeIgniter:密码验证

am46iovg  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(84)

我的确认有问题。我正在使用Codeigniter的Native Form Validation。
我正在做一个用户更新功能,但我无法验证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;

         }
}
r1zk6ea1

r1zk6ea11#

您在function password_check($str)中的条件不正确。更换

if($result)

if(!$result)

相关问题