codeigniter password_verify返回false

时间:2017-03-10 11:17:49

标签: php codeigniter

我不知道这是不是Codeigniter的问题,但是password_verify在我的其他网站(没有任何框架)上工作。但是在Codeigniter中,尽管密码正确,但password_verify始终返回false。我还没有找到解决方案,这是我的代码:

public function login()
{
    $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|alpha_numeric');
    $this->form_validation->set_rules('password','Password','required|trim');
    if($this->form_validation->run() == false)
    {
        $data['errors'] = validation_errors();
        $this->load->view('templates/header');
        $this->load->view('user/login',$data);
    } else {
        $username = $this->input->post('username',true);
        $password = $this->input->post('password');
        $query = $this->db
        ->select("*")
        ->from("users")
        ->where("username", $username)
        ->get();
         if($query->num_rows() != 1)  throw new UnexpectedValueException("Wrong user!");
         $row = $query->row();
        if(!password_verify($password,$row->password)) throw new UnexpectedValueException('22' . $row->password);
    }

public function register()
{
    //fields username,email,password1,password2
    // $this->load->view('templates/header');
    // $this->load->view('user/register');
    $this->form_validation->set_rules('username','Username','required|max_length[50]|is_unique[users.username]|trim|alpha_numeric');
    $this->form_validation->set_rules('email','Email', 'trim|required|valid_email|is_unique[users.email]');
    $this->form_validation->set_rules('password1', 'Password', 'required|trim');
    $this->form_validation->set_rules('password2','Confirm password','required|matches[password1]');
    if($this->form_validation->run() == false)
    {
        $data['errors'] = validation_errors();
        $this->load->view('templates/header');
        $this->load->view('user/register',$data);

    } else {
        $username = $this->input->post('username',true);
        $email = $this->input->post('email',true);
        $password = $this->input->post('password');
        if($this->user_model->create_user($username,$email,$password))
        {
            echo $password;
        }
    }
 }

每当我输入正确的密码时,都会抛出意外值异常:exception

0 个答案:

没有答案