Returning via an abstract protected function?

I am looking at the auth class in Kohana 3 as well as the login script. When the login page calls the auth class login function, it is returned via the protected abstract function _login. Why would you do this out of curiosity? I don't seem to understand what will actually matter, since you will be returning the same data anyway. One option floating around in my head is that when you come back through the protected snippet, you have to make sure that the data hasn't changed since it was entered into the auth-> login function and when it exited. I am trying to understand some of the nuances. Thanks.

 public function login($username, $password, $remember = FALSE)
 {
  if (empty($password))
   return FALSE;

  if (is_string($password))
  {
   // Get the salt from the stored password
   $salt = $this->find_salt($this->password($username));

   // Create a hashed password using the salt from the stored password
   $password = $this->hash_password($password, $salt);
  }

  return $this->_login($username, $password, $remember);
 }

      

and then....

 abstract protected function _login($username, $password, $remember);

      

+2


a source to share


1 answer


This is a weak example of a pattern design pattern. Every time someone wants to log in, there are always a few modifications and checks to be done on the variables. The password must not be empty. The password must be hashed.

The user then attempts to log on to the system. Now the reason this function is abstract is because the login procedure can be implemented in several ways; for several different databases, with or without sessions, etc.



The reason this function is protected is because you don't want anyone to call the particular _login implementation directly, without first doing the previous checks and changes (hash password, etc.).

So, to sum it up, it was coded to force all login requests to first check the length of the password and then hash the password before the actual implementation of the real login function is called.

+2


a source







All Articles