【问题标题】:CodeIgniter: Password ValidationCodeIgniter:密码验证
【发布时间】: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


    【解决方案1】:

    function password_check($str) 中的条件不正确。替换

    if($result)
    

    if(!$result)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 2012-06-03
      • 2017-10-17
      相关资源
      最近更新 更多