コード例 #1
0
 public function processLoginRequest(PhabricatorAuthLoginController $controller)
 {
     $request = $controller->getRequest();
     $viewer = $request->getUser();
     $response = null;
     $account = null;
     $username = $request->getStr('ldap_username');
     $password = $request->getStr('ldap_password');
     $has_password = strlen($password);
     $password = new PhutilOpaqueEnvelope($password);
     if (!strlen($username) || !$has_password) {
         $response = $controller->buildProviderPageResponse($this, $this->renderLoginForm($request, 'login'));
         return array($account, $response);
     }
     if ($request->isFormPost()) {
         try {
             if (strlen($username) && $has_password) {
                 $adapter = $this->getAdapter();
                 $adapter->setLoginUsername($username);
                 $adapter->setLoginPassword($password);
                 // TODO: This calls ldap_bind() eventually, which dumps cleartext
                 // passwords to the error log. See note in PhutilLDAPAuthAdapter.
                 // See T3351.
                 DarkConsoleErrorLogPluginAPI::enableDiscardMode();
                 $account_id = $adapter->getAccountID();
                 DarkConsoleErrorLogPluginAPI::disableDiscardMode();
             } else {
                 throw new Exception(pht('Username and password are required!'));
             }
         } catch (PhutilAuthCredentialException $ex) {
             $response = $controller->buildProviderPageResponse($this, $this->renderLoginForm($request, 'login'));
             return array($account, $response);
         } catch (Exception $ex) {
             // TODO: Make this cleaner.
             throw $ex;
         }
     }
     return array($this->loadOrCreateAccount($account_id), $response);
 }
コード例 #2
0
 public function processLoginRequest(PhabricatorAuthLoginController $controller)
 {
     $request = $controller->getRequest();
     $viewer = $request->getUser();
     $require_captcha = false;
     $captcha_valid = false;
     if (AphrontFormRecaptchaControl::isRecaptchaEnabled()) {
         $failed_attempts = PhabricatorUserLog::loadRecentEventsFromThisIP(PhabricatorUserLog::ACTION_LOGIN_FAILURE, 60 * 15);
         if (count($failed_attempts) > 5) {
             $require_captcha = true;
             $captcha_valid = AphrontFormRecaptchaControl::processCaptcha($request);
         }
     }
     $response = null;
     $account = null;
     $log_user = null;
     if ($request->isFormPost()) {
         if (!$require_captcha || $captcha_valid) {
             $username_or_email = $request->getStr('username');
             if (strlen($username_or_email)) {
                 $user = id(new PhabricatorUser())->loadOneWhere('username = %s', $username_or_email);
                 if (!$user) {
                     $user = PhabricatorUser::loadOneWithEmailAddress($username_or_email);
                 }
                 if ($user) {
                     $envelope = new PhutilOpaqueEnvelope($request->getStr('password'));
                     if ($user->comparePassword($envelope)) {
                         $account = $this->loadOrCreateAccount($user->getPHID());
                         $log_user = $user;
                         // If the user's password is stored using a less-than-optimal
                         // hash, upgrade them to the strongest available hash.
                         $hash_envelope = new PhutilOpaqueEnvelope($user->getPasswordHash());
                         if (PhabricatorPasswordHasher::canUpgradeHash($hash_envelope)) {
                             $user->setPassword($envelope);
                             $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
                             $user->save();
                             unset($unguarded);
                         }
                     }
                 }
             }
         }
     }
     if (!$account) {
         if ($request->isFormPost()) {
             $log = PhabricatorUserLog::initializeNewLog(null, $log_user ? $log_user->getPHID() : null, PhabricatorUserLog::ACTION_LOGIN_FAILURE);
             $log->save();
         }
         $request->clearCookie(PhabricatorCookies::COOKIE_USERNAME);
         $response = $controller->buildProviderPageResponse($this, $this->renderPasswordLoginForm($request, $require_captcha, $captcha_valid));
     }
     return array($account, $response);
 }