We are implementing a register and login module for our project, my teammate used the codeigniter encryption service $this->encryption->encrypt($this->input->post('passw')) for our password. The problem is with our login, we can’t seem to decrypt or read it. Little help?
Login function in controller:
> public function log_validation()
{
$this->form_validation->set_rules('emp_id', 'emp_id', 'required');
$this->form_validation->set_rules('passw', 'passw', 'required');
if ($this->form_validation->run() == FALSE){
echo "<script>alert('Login Error!')</script>";
$data['title'] = 'Login';
$this->load->view('include/header', $data);
$this->load->view('user/login');
}
else{
$empid = $this->input->post("emp_id");
$password = $this->encryption->decrypt($this->input->post('passw'));
$key = 'mykey';
$decryptpass = $this->encryption->decrypt($password, $key);
//function in model to get employee id and password
$emp_ref = $this->Users_model->verify_employee($empid, $decryptpass );
if($emp_ref == NULL){
echo "<script>alert('Member not found')</script>";
redirect('Users/login_user', 'refresh');
}elseif($emp_ref[0]->col_role == 1){
$this->session->set_userdata("emp_id", $emp_ref[0]->col_emp_id);
redirect('Users/dashboarda', 'refresh');
}elseif($emp_ref[0]->col_role == 2){
$this->session->set_userdata("emp_id", $emp_ref[0]->col_emp_id);
redirect('Users/dashboard', 'refresh');
}elseif($emp_ref[0]->col_role == 3){
$this->session->set_userdata("emp_id", $emp_ref[0]->col_emp_id);
redirect('Users/dashboard0', 'refresh');
}
}
}
the model there is:
public function verify_employee($empid, $password){
$this->db->select('col_role, col_emp_id, col_password');
$this->db->where('col_emp_id', $empid);
$this->db->where('col_password', $password);
$query = $this->db->get($this->tbl_management_accounts);
if($query->result() == NULL)
{
return NULL;
}
else
{
return $query->result();
}
}