Ejemplo n.º 1
0
 /**
  * Authenticate user
  *
  * @param string $login    Login
  * @param string $password Password
  *
  * @return boolean
  */
 public function authenticate($login, $password)
 {
     $authAdapter = new Adapter\DbTable\CredentialTreatmentAdapter($this->getAdapter());
     $authAdapter->setTableName($this->name);
     $authAdapter->setIdentityColumn('login');
     $authAdapter->setCredentialColumn('password');
     $authAdapter->setCredentialTreatment('? AND active = TRUE');
     $authAdapter->setIdentity($login);
     $authAdapter->setCredential(sha1($password));
     $auth = new AuthenticationService(new Storage\Session(self::BACKEND_AUTH_NAMESPACE));
     $result = $auth->authenticate($authAdapter);
     $this->events()->trigger(__CLASS__, 'before.auth', $this);
     if ($result->isValid()) {
         $data = $authAdapter->getResultRowObject(null, 'password');
         $this->setData((array) $data);
         $this->setOrigData();
         $auth->getStorage()->write($this);
         $this->events()->trigger(__CLASS__, 'after.auth', $this);
         return true;
     }
     $this->events()->trigger(__CLASS__, 'after.auth.failed', $this, array('login' => $login));
     return false;
 }