Php codeigniter密码\u验证返回false
我不知道这是否是Codeigniter的问题,但password_verify在我的其他网站(没有任何框架)上工作。然而,在Codeigniter中,尽管密码正确,密码验证始终返回false。我尚未找到解决方案,以下是我的代码:Php codeigniter密码\u验证返回false,php,codeigniter,Php,Codeigniter,我不知道这是否是Codeigniter的问题,但password_verify在我的其他网站(没有任何框架)上工作。然而,在Codeigniter中,尽管密码正确,密码验证始终返回false。我尚未找到解决方案,以下是我的代码: public function login() { $this->form_validation->set_rules('username','Username','required|trim|max_length[50]|alpha_numeric
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;
}
}
}
每当我输入正确的密码时,就会引发意外的值异常:数据库中密码字段的大小是多少?@Naincy varchar(100)您能分享上面哈希的密码吗…这样我就可以试试…@Naincy我知道您的答案了。。我没想到。是ASD123,请检查一下