Hi i am struggling with a problem the past days on the verification part of the user input password at log in. First to mentioned that i used an exteal library for codeigniter for the hashing of the password. The problem is when i get the hashed password from the database and use a library function that compares the raw password input of the user with the one from the database it retus false. I think i have tried and checked every possibility of error but i couldn't find an answer. I even checked if the lenght of the string was the problem, i tried also to change the lenght, the type(varchar,char) or even the collation of the password field in phpmyadmin but still no results. In my tries i thought that maybe there is a problem with the codeigniter library that i found so i decided to use the native php functions of brcypt in order to be sure. But the same problem consists at the point where the two passwords(hashed and raw input)are compared. I also tried just to hardcode the password then hash it and then compare the raw with the hashed one with the php verify function and surprisingly it retued true so i am confused what is going wrong and with the hashed password from the database it retus false but with the one that is been hashed and compared instanlty retus true. Both (codeigniter library and native php functions)work fine with way that are hashed and compared instantly. By the way just to mentioned it my php version is 5.6.10 I am at a deadend and out of ideas so any help will be appreciated guys.
This is the library that i used
Everything is for test purposes so what i am providing is for testing if it works. My code is similiar
Test model that retrieves the hashed password and retus it to the controller in order to be compared with the hard coded password which is the same as the one provided on the register. Please ignore the Idea
public function login_user($email){
//Validate
$this->db->where('email',$email);
//$this->db->where('password',$enc_password);
$result = $this->db->get('users');
if($result->num_rows() == 1){
$row = $result->row();
}
retu $row->password;
} else {
retu false;
}
}
Test controller
public function login()
{
$this->load->model('test_model');
$email = "minas@live.com";
$password = '12345';
$test1 = $this->test_model->login_user($email,$password);
//$options = [
//'cost' => 10,
//];
//$hash_password = password_hash($password, PASSWORD_BCRYPT, $options);
if(password_verify($password, $test1)){
$query_data['test']="it works";
}else{
$query_data['test']="not works";
}
//$this->load->view('templates/header');
$this->load->view('view_test2',$query_data);
//$this->load->view('templates/footer_movie_list_full');
My hash when i am creating the user
public function create_member(){
$password = $this->input->post('password');
$options = [
'cost' => 10
];
$hash_password = password_hash($password, PASSWORD_BCRYPT, $options);
$new_member_insert = array(
'firstname' => $this->input->post('user_firstname'),
'lastname' => $this->input->post('user_lastname'),
'email' => $this->input->post('user_email'),
'password' => $hash_password
);
$insert = $this->db->insert('users', $new_member_insert);
retu $insert;
}
}
For the validation i am using the set rules function of codeigniter which is executed before anything comes to the post that i am using in database. Please help me as i am stuck as i don't know what else to do.
