Пример #1
0
 public function authenticate($username, $password)
 {
     $callback = function ($password, $hash) {
         $bcrypt = new Bcrypt();
         return $bcrypt->verify($hash, $password);
     };
     $authenticationService = new AuthenticationService();
     $callbackCheckAdapter = new CallbackCheckAdapter($this->dbAdapter, "users", 'username', 'password', $callback);
     $callbackCheckAdapter->setIdentity($username)->setCredential($password);
     $authenticationService->setAdapter($callbackCheckAdapter);
     $authResult = $authenticationService->authenticate();
     if ($authResult->isValid()) {
         $userObject = $callbackCheckAdapter->getResultRowObject();
         $authenticationService->getStorage()->write($userObject);
         if ($userObject->status == 0) {
             $authenticationService->clearIdentity();
             $this->setCode(-5);
             return false;
         } else {
             return true;
         }
     } else {
         $this->setCode($authResult->getCode());
         return false;
     }
 }