I want to hash my passwords in codeigniter.I can't find a way around it
this is my insert model.the password is encrypted when inserting the client details.
I cant decrypt it when logging in
What I have tried:
<pre>public function insert_client($codeDigits)
{
$hash = $this->hash($_POST['Password']);
$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 = $hash;
$this->PhoneNo = $_POST['PhoneNo'];
$this->confirmCode = $codeDigits;
$this->db->insert('users', $this);
$returned = true;
}
return $returned;
}
this is my password hash model
public function hash($password)
{
$hash = password_hash($password,PASSWORD_DEFAULT);
return $hash;
}
public function verifyHash($password,$vpassword)
{
if(password_verify($password,$vpassword))
{
return TRUE;
}
else{
return FALSE;
}
}
during login i can't decrypt the password,the password get encrypted in the database correctly anyway.
public function login_model($email,$password)
{
$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)
{
$results = $query->row();
foreach($results as $data)
{
if($this->verifyHash($this->$password,$data->password == TRUE))
{
$dat = array(
'id_user' => $data->id_User,
'FirstName' => $data->FirstName,
'LastName' => $data->LastName,
'Phonenumber' => $data->PhoneNo,
'Email' => $data->Email,
'role' => $data->Role_Id,
'imageUrl' => $data->imageUrl,
'category_id' => $data->category_id,
'IdType' => $data->IdType,
'IdNumber' => $data->IdNumber,
'DOB' => $data->DOB,
'confirmCode' => $data->confirmCode,
'confirmed' => $data->confirmed,
'Points'=> $data->Points
);
}
$this->session->set_userdata($dat);
return true;
}
}
else{
return false;
}
}
this is my login function in the controller
public function post_login()
{
$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_model($_POST['Email'],$_POST['Password'])){
if($_SESSION['confirmed'] == true) {
if ($_SESSION['role'] == 2) {
redirect("Client/welcome");
} else if ($_SESSION['role'] == 3) {
redirect("Pro/welcome");
}
}else{
redirect("Welcome/confirmCode");
}
}else{
$this->session->set_flashdata('err', true);
redirect("Welcome/login");
}
}else{
$this->login();
}
}
How can I decrypt the password when logging in.