array( 'not_empty' => NULL, 'min_length' => array(4), 'max_length' => array(8), ), 'password' => array( 'not_empty' => NULL, 'min_length' => array(5), 'max_length' => array(16), ), 'password_confirm' => array( 'matches_ifset' => array('password'), ), ); // Columns to ignore protected $_ignored_columns = array('password_confirm'); // Field labels protected $_labels = array( 'admin_name' => 'username', 'email' => 'email address', 'password' => 'password', 'password_confirm' => 'password confirmation', ); /** * Validates login information from an array, and optionally redirects * after a successful login. * * @param array values to check * @param string URI or URL to redirect to * @return boolean */ public function login(array & $array, $redirect = FALSE) { $fieldname = 'admin_name'; // @todo This should be defined in a config or database driver file $array = Validate::factory($array) ->label('username', $this->_labels[$fieldname]) ->label('password', $this->_labels['password']) ->filter(TRUE, 'trim') ->filter('username','strtoupper') ->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('admin_name', 'invalid'); } } return $status; } } ?>