Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 密码散列和密码点火器_Php_Mysqli_Codeigniter 3 - Fatal编程技术网

Php 密码散列和密码点火器

Php 密码散列和密码点火器,php,mysqli,codeigniter-3,Php,Mysqli,Codeigniter 3,我可以在用户注册期间对密码进行哈希运算,但是将登录期间用户输入的密码与数据库中的密码进行比较不起作用。获取错误。 这是注册的插页。请告诉我哪里出了问题 public function insert_client($codeDigits) { $options = ['cost'=>12]; $response = $this->taken_email($_POST['Email']); if($response){ $returned =

我可以在用户注册期间对密码进行哈希运算,但是将登录期间用户输入的密码与数据库中的密码进行比较不起作用。获取错误。 这是注册的插页。请告诉我哪里出了问题

 public function insert_client($codeDigits)
 {
    $options = ['cost'=>12];
    $response = $this->taken_email($_POST['Email']);
    if($response){
        $returned = false;
    }else{
            $this->FirstName    = $_POST['FirstName']; 
            $this->LastName    = $_POST['LastName'];
            $this->Email     = $_POST['Email'];  
            $this->Role_Id     = 2;  
            $this->Password =  password_hash($_POST['Password'],PASSWORD_BCRYPT,$options);
            $this->PhoneNo    = $_POST['PhoneNo'];
            $this->confirmCode    = $codeDigits;
            $this->db->insert('users', $this);
            $returned = true;
        }            
        return $returned;
    }
这是登录模型,用于登录的查询

 public function login_model2($email,$password)
 {   
   $options = ['cost'=>12];
   $this->db->select('*');
   $this->db->from('users');
   $this->db->where('Email',$email);
   //$this->db->where('Password',$password);
   $this->db->where('Role_Id !=',1);
   $query = $this->db->get();

   if($query->num_rows() > 0)
   {
       $data = $query->row(); 

       // storing the results in the variable $data        
           if(password_verify($password,$data->password))
           {           
              return true;
            }            
            else
            {
                return false;
                }                 
   }

   else
    {
       return false;
       }       
   }
这是登录时的登录控制器功能

 public function post_login2()
{
    $this->form_validation->set_rules('Email', 'Email', 'trim|required|min_length[6]');
    $this->form_validation->set_rules('Password', 'Password', 'trim|required|min_length[6]');

    if($this->form_validation->run() == TRUE ){ 
        if($this->Users_model->login_model2($_POST['Email'],$_POST['Password']))
        {
            //test for redirect

            if ($_SESSION['role'] == 2) {

                redirect("Client/welcome");

            } else if ($_SESSION['role'] == 3) {

                redirect("Pro/welcome");

            }

          // test for redirect
        }else{
            // 
            $this->session->set_flashdata('err', true);
            redirect("Welcome/login");
        }

    }else{

        $this->login();
    }
}
只需将
$data->password
更改为
$data->password

在model
login\u model2()
中,
password\u verify
应如下所示:

if(password_verify($password,$data->Password))
{           
   return true;
}            
else
{
   return false;
} 

您遇到了什么错误:或者简单地将$data->password更改为$data->password
if(密码验证($password$data->password))
中的
$returned
函数在if-else语句之前应该有一个初始化值,类似于
$returned=null
$returned=false
。。这似乎是你的错误之一。