首页 > 解决方案 > codeigniter中的Bcrypt散列

问题描述

我正在开发一些以前使用 md5 进行密码散列的 codeigniter webapp,我想更改为 Bcrypt。我已经成功地对密码进行了哈希处理,但我似乎无法理解为什么即使密码错误,登录代码也会返回 true。任何密码都将登录...我仍在学习 php,所以请多多关照。

这是我的登录功能

public function login()
{
      $email= $this->input->post('email', TRUE);
      $password= $this->input->post('password', TRUE);

 $data['email']= $email;
      $data['password']= password_verify($this->input->post('password', TRUE), PASSWORD_DEFAULT);
      $sess_array=array();
      $getdata=$this->Api_model->getSingleRow('admin',$data);
      if($getdata)
      {           
        if($getdata->status==1)
        {
          $this->session->unset_userdata($sess_array);
          $sess_array = array(
           'name' => $getdata->name,
           'id' => $getdata->id,
         );

         $this->session->set_userdata( $sess_array);
          $dataget['get_data'] =$getdata;
          $dataget['see_data'] =$sess_array;
          redirect('Admin/home');    
        }
        else
        {
          $this->session->set_flashdata('block', ' Contact to admin.');
            redirect('');
        }
      }
      else
      {
        $this->session->set_flashdata('msg', 'Please enter valid Username or Password');
        redirect('');
      }
    } ```



这是密码的注册码



$data['password']= password_hash($this->input->post('password', TRUE),PASSWORD_DEFAULT) ;

标签: phpcodeigniterhashbcrypt

解决方案


推荐阅读