Welcome Guest, Not a member yet? Register   Sign In
Custom errors
#1

[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?
#2

[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;
  }
}




Theme © iAndrew 2016 - Forum software by © MyBB