dadamssg Posted January 9, 2010 Share Posted January 9, 2010 im trying to get a simple login to work with a callback function i created to make sure the password the person entered matches a username they entered in a form. right now if i leave the fields blank and push submit i get “Empty fields”, which is right. But if i enter something in both…i get “It WORKED.”...which it doesn’t work. The username and password im entering do not match so it should return FALSE. any help please? <?php class Login extends Controller { function Login() { parent::Controller(); $this->load->database(); $this->load->library('session'); $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); } function index() { $this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean|callback_username_check'); $this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|'); if ($this->form_validation->run() == FALSE) { $this->session->set_flashdata('message', 'Empty Fields.'); redirect('mains'); } else { $this->session->set_flashdata('message', 'It WORKED.'); redirect('mains'); } function username_check() { $user = $this->input->post('username'); $pass = $this->input->post('password'); $query = $this->db->query("SELECT loginName,active FROM Member WHERE loginName='$user' AND password=md5('$pass')"); if($query->num_rows() == 1) { return TRUE; } else { return FALSE; } } } } ?> Link to comment https://forums.phpfreaks.com/topic/187808-codeigniter-login-help-please/ Share on other sites More sharing options...
didier8134 Posted January 11, 2010 Share Posted January 11, 2010 Mmm, I don't know this framework, but I'm going to assume the problem here. First of all, you should change the SQL to be something like: SELECT loginName FROM Member WHERE active AND (etc) - That is if the active is a bool field (1 or 0) in the db. Secondly, you might want to change the code to this: if($query->num_rows() === 1) Depending on what datatype the function returns... Where and how is the username_check function called? Link to comment https://forums.phpfreaks.com/topic/187808-codeigniter-login-help-please/#findComment-992770 Share on other sites More sharing options...
dominicd Posted January 15, 2010 Share Posted January 15, 2010 because your returning it as true when input is put in regardless of the data entered. Link to comment https://forums.phpfreaks.com/topic/187808-codeigniter-login-help-please/#findComment-995510 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.