CodeIgniter Forums
Custom errors - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Custom errors (/showthread.php?tid=5351)



Custom errors - El Forum - 01-18-2008

[eluser]williamparry[/eluser]
I'm wondering how to do a login using a custom error check. Do I append a custom callback error check to the username field?


Custom errors - El Forum - 01-18-2008

[eluser]Michael Wales[/eluser]
Code:
function index() {
  $this->load->library('validation');
  $rules['username'] = 'callback__check_login';
  $rules['password'] = '';
  $this->validation->set_rules($rules);
  // ... more code here ... //

  if ($this->validation->run()) {
    // Login was valid
  } else {
    // Login invalid or the form was not submitted
  }
}

function _check_login($username) {
  // Get our password, you can use any of the following - they are all the same at this point:
  // -  $this->validation->password;
  // -  $this->input->post('password');
  // -  $_POST['password'];
  $password = md5($_POST['password']);
  // ... SQL to determine if it's a good login or not ..

  if ($login === TRUE) {
    return TRUE;
  } else {
    $this->validation->set_message('_check_login', 'Bad username/password');
    return FALSE;
  }
}