I have this helper to encrpyt my password
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
* This function used to generate the hashed password
* @param {string} $plainPassword : This is plain text password
*/
if(!function_exists('getHashedPassword'))
{
function getHashedPassword($plainPassword)
{
return password_hash($plainPassword, PASSWORD_DEFAULT);
}
}
/**
* This function used to generate the hashed password
* @param {string} $plainPassword : This is plain text password
* @param {string} $hashedPassword : This is hashed password
*/
if(!function_exists('verifyHashedPassword'))
{
function verifyHashedPassword($plainPassword, $hashedPassword)
{
return password_verify($plainPassword, $hashedPassword) ? true : false;
}
}
?>
Now I don't have any problem storing the hashed password to my database and I am doing it like this
on my model
function saveAccount($userinfo)
{
$data = array(
'username' => $this->input->post('username'),
'password' => $userinfo,
'type' => $this->input->post('accountType')
);
return $this->db->insert('users', $data);
}
and on my controller
$userInfo = getHashedPassword($this->input->post('password'));
$this->employee->saveAccount($userInfo);
Now this registration process is currently working and I don't have any problem storing it on my database now my problem is that whenever I tried to login to the user i currently registered for like example .
username : admin5
password : admin5 (which is encrypted on my database)
on my controller for logging in
$username = $this->input->post('username');
$password = $this->input->post('password');
$user_data = $this->employee->can_login($username,$password);
and on my model
function can_login($username, $password)
{
$this->db->where('username', $username);
$this->db->where('password', $password);
$query = $this->db->get('users');
$user = $query->result();
verifyHashedPassword($password, $user[0]->password);
if($query->num_rows() > 0)
{
return $query->row_array();
}
else
{
return false;
}
}
what do you think could be the problem ?