One fun thing with Zend framework is to build your own authentication provider. It’s needed for exemple if you do not plan to use a database or if you want to use a highly secure authentication provider like a smartcard, or a one time pad. In that scenario you might want to use authentication via a webservice to make sure your servers a in different compartiments. Here’s the base of a simple authentication provider :

  1. class MyAuthenticationAdapter implements Zend_Auth_Adapter_Interface
  2. {
  3. private $email ;
  4. private $password;
  5. public function __construct($email,$password)
  6. {
  7. $this->email = $email;
  8. $this->password = $password;
  9. }
  10. public function authenticate()
  11. {
  12. $Users = new Users();
  13. if($Users->Authenticate($this->email, $this->password))
  14. $authResult[‘code’] = Zend_Auth_Result::SUCCESS;
  15. else
  16. $authResult[‘code’] = Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND;
  17. return new Zend_Auth_Result($authResult[‘code’],$this->email);
  18. }
  19. }

Not so hard after all !

Advertisements