[eluser]Unknown[/eluser]
Hi Ortonruk
I have same problem like you exactly with almost same code.
Whatever I type password in, l can go though the login process. It seems like my callback_password_check function is not working.
I also had 2 same hashing codes (I copied and pasted it from somewhere) so I delete it one of hashing codes in both signup controller and login controller.
I signed up new and tried to login in again. But I still face the same issue
So how did you solve it? By removing re-hashing code?
It's couple months ago thread butI hope you see it.
Here is my code:
Code:
<?php
class C_account extends CI_Controller
{
function C_account()
{
parent::__construct();
$this->load->helper(array('html','form'));
$this->load->library(array('form_validation', 'encrypt'));
$this->_salt = "123456789987654321";
}
function login()
{
$this->form_validation->set_rules('email', 'Email', 'trim|xss_clean|required|callback_email_check');
$this->form_validation->set_rules('password', 'Password', 'trim|xss_clean|required|min_length[4]|max_length[12]|callback_password_check');
$this->_email = $this->input->post('email');
//Just for debbuging
//$data['pw0'] = "pw0:".$this->input->post('password');
$this->_password = sha1($this->_salt . $this->input->post('password'));
$data['pw'] = $this->_password;
if($this->form_validation->run() == FALSE)
{
$this->load->view('v_login', $data);
}
else
{
//Just for debbuging
//$data['pw2'] = $this->password_check();
$this->load->view('test', $data);
$this->load->view('test2');
}
}
function email_check()
{
$query = $this->db->get_where('users', array('email' => $this->_email));
if($query->num_rows() > 0)
{
return TRUE;
}
$this->form_validation->set_message('email_check', 'The username is not in database!');
return FALSE;
}
function password_check()
{
$this->db->where('email', $this->_email);
$query = $this->db->get('users');
$result = $query->row_array();
if($query->num_rows() == 0)
{
$this->form_validation->set_message('password_check', 'The password is wrong.');
return FALSE;
}
if($result['password'] == $this->_password)
{
return TRUE;
}
}
}
?>