public function login(array &$array, $redirect = FALSE)
{
$fieldname = $this->unique_key($array['username']);
$array = Validate::factory($array)->label('username', $this->_labels[$fieldname])->label('password', $this->_labels['password'])->filter(TRUE, 'trim')->rules('username', $this->_rules[$fieldname])->rules('password', $this->_rules['password']);
// Get the remember login option
$remember = isset($array['remember']);
// Login starts out invalid
$status = FALSE;
if ($array->check()) {
// Attempt to load the user
$this->where($fieldname, '=', $array['username'])->find();
if ($this->loaded() and Auth::instance()->login($this, $array['password'], $remember)) {
if (is_string($redirect)) {
// Redirect after a successful login
Request::instance()->redirect($redirect);
}
// Login is successful
$status = TRUE;
} else {
$array->error('username', 'invalid');
}
}
return $status;
}