當前位置: 首頁>>代碼示例>>PHP>>正文


PHP PhabricatorHash::digest方法代碼示例

本文整理匯總了PHP中PhabricatorHash::digest方法的典型用法代碼示例。如果您正苦於以下問題:PHP PhabricatorHash::digest方法的具體用法?PHP PhabricatorHash::digest怎麽用?PHP PhabricatorHash::digest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PhabricatorHash的用法示例。


在下文中一共展示了PhabricatorHash::digest方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getMarkupFieldKey

 /**
  * @task markup
  */
 public function getMarkupFieldKey($field)
 {
     if ($this->shouldUseMarkupCache($field)) {
         $id = $this->getID();
     } else {
         $id = PhabricatorHash::digest($this->getMarkupText($field));
     }
     return "phriction:{$field}:{$id}";
 }
開發者ID:fengshao0907,項目名稱:phabricator,代碼行數:12,代碼來源:PhrictionContent.php

示例2: setSession

 public function setSession($session)
 {
     // Store the hash of the session, not the actual session key, so that
     // seeing the logs doesn't compromise all the sessions which appear in
     // them. This just prevents casual leaks, like in a screenshot.
     if (strlen($session)) {
         $this->session = PhabricatorHash::digest($session);
     }
     return $this;
 }
開發者ID:netcomtec,項目名稱:phabricator,代碼行數:10,代碼來源:PhabricatorUserLog.php

示例3: newHTTPAuthorization

 public static function newHTTPAuthorization(PhabricatorRepository $repository, PhabricatorUser $viewer, $operation)
 {
     $lfs_user = self::HTTP_USERNAME;
     $lfs_pass = Filesystem::readRandomCharacters(32);
     $lfs_hash = PhabricatorHash::digest($lfs_pass);
     $ttl = PhabricatorTime::getNow() + phutil_units('1 day in seconds');
     $token = id(new PhabricatorAuthTemporaryToken())->setTokenResource($repository->getPHID())->setTokenType(self::TOKENTYPE)->setTokenCode($lfs_hash)->setUserPHID($viewer->getPHID())->setTemporaryTokenProperty('lfs.operation', $operation)->setTokenExpires($ttl)->save();
     $authorization_header = base64_encode($lfs_user . ':' . $lfs_pass);
     return 'Basic ' . $authorization_header;
 }
開發者ID:rchicoli,項目名稱:phabricator,代碼行數:10,代碼來源:DiffusionGitLFSTemporaryTokenType.php

示例4: digestPassword

 /**
  * Digest a string into a password hash. This is similar to @{method:digest},
  * but requires a salt and iterates the hash to increase cost.
  */
 public static function digestPassword(PhutilOpaqueEnvelope $envelope, $salt)
 {
     $result = $envelope->openEnvelope();
     if (!$result) {
         throw new Exception('Trying to digest empty password!');
     }
     for ($ii = 0; $ii < 1000; $ii++) {
         $result = PhabricatorHash::digest($result, $salt);
     }
     return $result;
 }
開發者ID:denghp,項目名稱:phabricator,代碼行數:15,代碼來源:PhabricatorHash.php

示例5: processAddFactorForm

 public function processAddFactorForm(AphrontFormView $form, AphrontRequest $request, PhabricatorUser $user)
 {
     $totp_token_type = PhabricatorAuthTOTPKeyTemporaryTokenType::TOKENTYPE;
     $key = $request->getStr('totpkey');
     if (strlen($key)) {
         // If the user is providing a key, make sure it's a key we generated.
         // This raises the barrier to theoretical attacks where an attacker might
         // provide a known key (such attacks are already prevented by CSRF, but
         // this is a second barrier to overcome).
         // (We store and verify the hash of the key, not the key itself, to limit
         // how useful the data in the table is to an attacker.)
         $temporary_token = id(new PhabricatorAuthTemporaryTokenQuery())->setViewer($user)->withTokenResources(array($user->getPHID()))->withTokenTypes(array($totp_token_type))->withExpired(false)->withTokenCodes(array(PhabricatorHash::digest($key)))->executeOne();
         if (!$temporary_token) {
             // If we don't have a matching token, regenerate the key below.
             $key = null;
         }
     }
     if (!strlen($key)) {
         $key = self::generateNewTOTPKey();
         // Mark this key as one we generated, so the user is allowed to submit
         // a response for it.
         $unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
         id(new PhabricatorAuthTemporaryToken())->setTokenResource($user->getPHID())->setTokenType($totp_token_type)->setTokenExpires(time() + phutil_units('1 hour in seconds'))->setTokenCode(PhabricatorHash::digest($key))->save();
         unset($unguarded);
     }
     $code = $request->getStr('totpcode');
     $e_code = true;
     if ($request->getExists('totp')) {
         $okay = self::verifyTOTPCode($user, new PhutilOpaqueEnvelope($key), $code);
         if ($okay) {
             $config = $this->newConfigForUser($user)->setFactorName(pht('Mobile App (TOTP)'))->setFactorSecret($key);
             return $config;
         } else {
             if (!strlen($code)) {
                 $e_code = pht('Required');
             } else {
                 $e_code = pht('Invalid');
             }
         }
     }
     $form->addHiddenInput('totp', true);
     $form->addHiddenInput('totpkey', $key);
     $form->appendRemarkupInstructions(pht('First, download an authenticator application on your phone. Two ' . 'applications which work well are **Authy** and **Google ' . 'Authenticator**, but any other TOTP application should also work.'));
     $form->appendInstructions(pht('Launch the application on your phone, and add a new entry for ' . 'this Phabricator install. When prompted, scan the QR code or ' . 'manually enter the key shown below into the application.'));
     $prod_uri = new PhutilURI(PhabricatorEnv::getProductionURI('/'));
     $issuer = $prod_uri->getDomain();
     $uri = urisprintf('otpauth://totp/%s:%s?secret=%s&issuer=%s', $issuer, $user->getUsername(), $key, $issuer);
     $qrcode = $this->renderQRCode($uri);
     $form->appendChild($qrcode);
     $form->appendChild(id(new AphrontFormStaticControl())->setLabel(pht('Key'))->setValue(phutil_tag('strong', array(), $key)));
     $form->appendInstructions(pht('(If given an option, select that this key is "Time Based", not ' . '"Counter Based".)'));
     $form->appendInstructions(pht('After entering the key, the application should display a numeric ' . 'code. Enter that code below to confirm that you have configured ' . 'the authenticator correctly:'));
     $form->appendChild(id(new PHUIFormNumberControl())->setLabel(pht('TOTP Code'))->setName('totpcode')->setValue($code)->setError($e_code));
 }
開發者ID:endlessm,項目名稱:phabricator,代碼行數:54,代碼來源:PhabricatorTOTPAuthFactor.php

示例6: processRequest

 public function processRequest(AphrontRequest $request)
 {
     $viewer = $request->getUser();
     $accounts = id(new PhabricatorExternalAccountQuery())->setViewer($viewer)->withUserPHIDs(array($viewer->getPHID()))->requireCapabilities(array(PhabricatorPolicyCapability::CAN_VIEW, PhabricatorPolicyCapability::CAN_EDIT))->execute();
     $identity_phids = mpull($accounts, 'getPHID');
     $identity_phids[] = $viewer->getPHID();
     $sessions = id(new PhabricatorAuthSessionQuery())->setViewer($viewer)->withIdentityPHIDs($identity_phids)->execute();
     $handles = id(new PhabricatorHandleQuery())->setViewer($viewer)->withPHIDs($identity_phids)->execute();
     $current_key = PhabricatorHash::digest($request->getCookie(PhabricatorCookies::COOKIE_SESSION));
     $rows = array();
     $rowc = array();
     foreach ($sessions as $session) {
         $is_current = phutil_hashes_are_identical($session->getSessionKey(), $current_key);
         if ($is_current) {
             $rowc[] = 'highlighted';
             $button = phutil_tag('a', array('class' => 'small grey button disabled'), pht('Current'));
         } else {
             $rowc[] = null;
             $button = javelin_tag('a', array('href' => '/auth/session/terminate/' . $session->getID() . '/', 'class' => 'small grey button', 'sigil' => 'workflow'), pht('Terminate'));
         }
         $hisec = $session->getHighSecurityUntil() - time();
         $rows[] = array($handles[$session->getUserPHID()]->renderLink(), substr($session->getSessionKey(), 0, 6), $session->getType(), $hisec > 0 ? phutil_format_relative_time($hisec) : null, phabricator_datetime($session->getSessionStart(), $viewer), phabricator_date($session->getSessionExpires(), $viewer), $button);
     }
     $table = new AphrontTableView($rows);
     $table->setNoDataString(pht("You don't have any active sessions."));
     $table->setRowClasses($rowc);
     $table->setHeaders(array(pht('Identity'), pht('Session'), pht('Type'), pht('HiSec'), pht('Created'), pht('Expires'), pht('')));
     $table->setColumnClasses(array('wide', 'n', '', 'right', 'right', 'right', 'action'));
     $terminate_icon = id(new PHUIIconView())->setIconFont('fa-exclamation-triangle');
     $terminate_button = id(new PHUIButtonView())->setText(pht('Terminate All Sessions'))->setHref('/auth/session/terminate/all/')->setTag('a')->setWorkflow(true)->setIcon($terminate_icon);
     $header = id(new PHUIHeaderView())->setHeader(pht('Active Login Sessions'))->addActionLink($terminate_button);
     $hisec = $viewer->getSession()->getHighSecurityUntil() - time();
     if ($hisec > 0) {
         $hisec_icon = id(new PHUIIconView())->setIconFont('fa-lock');
         $hisec_button = id(new PHUIButtonView())->setText(pht('Leave High Security'))->setHref('/auth/session/downgrade/')->setTag('a')->setWorkflow(true)->setIcon($hisec_icon);
         $header->addActionLink($hisec_button);
     }
     $panel = id(new PHUIObjectBoxView())->setHeader($header)->setTable($table);
     return $panel;
 }
開發者ID:patelhardik,項目名稱:phabricator,代碼行數:40,代碼來源:PhabricatorSessionsSettingsPanel.php

示例7: buildWhereClause

 protected function buildWhereClause(AphrontDatabaseConnection $conn_r)
 {
     $where = array();
     if ($this->ids) {
         $where[] = qsprintf($conn_r, 'id IN (%Ld)', $this->ids);
     }
     if ($this->identityPHIDs) {
         $where[] = qsprintf($conn_r, 'userPHID IN (%Ls)', $this->identityPHIDs);
     }
     if ($this->sessionKeys) {
         $hashes = array();
         foreach ($this->sessionKeys as $session_key) {
             $hashes[] = PhabricatorHash::digest($session_key);
         }
         $where[] = qsprintf($conn_r, 'sessionKey IN (%Ls)', $hashes);
     }
     if ($this->sessionTypes) {
         $where[] = qsprintf($conn_r, 'type IN (%Ls)', $this->sessionTypes);
     }
     $where[] = $this->buildPagingClause($conn_r);
     return $this->formatWhereClause($where);
 }
開發者ID:pugong,項目名稱:phabricator,代碼行數:22,代碼來源:PhabricatorAuthSessionQuery.php

示例8: handleRequest

 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $this->getViewer();
     $id = $request->getURIData('id');
     $is_all = $id === 'all';
     $query = id(new PhabricatorAuthSessionQuery())->setViewer($viewer)->withIdentityPHIDs(array($viewer->getPHID()));
     if (!$is_all) {
         $query->withIDs(array($id));
     }
     $current_key = PhabricatorHash::digest($request->getCookie(PhabricatorCookies::COOKIE_SESSION));
     $sessions = $query->execute();
     foreach ($sessions as $key => $session) {
         $is_current = phutil_hashes_are_identical($session->getSessionKey(), $current_key);
         if ($is_current) {
             // Don't terminate the current login session.
             unset($sessions[$key]);
         }
     }
     $panel_uri = '/settings/panel/sessions/';
     if (!$sessions) {
         return $this->newDialog()->setTitle(pht('No Matching Sessions'))->appendParagraph(pht('There are no matching sessions to terminate.'))->appendParagraph(pht('(You can not terminate your current login session. To ' . 'terminate it, log out.)'))->addCancelButton($panel_uri);
     }
     if ($request->isDialogFormPost()) {
         foreach ($sessions as $session) {
             $session->delete();
         }
         return id(new AphrontRedirectResponse())->setURI($panel_uri);
     }
     if ($is_all) {
         $title = pht('Terminate Sessions?');
         $short = pht('Terminate Sessions');
         $body = pht('Really terminate all sessions? (Your current login session will ' . 'not be terminated.)');
     } else {
         $title = pht('Terminate Session?');
         $short = pht('Terminate Session');
         $body = pht('Really terminate session %s?', phutil_tag('strong', array(), substr($session->getSessionKey(), 0, 6)));
     }
     return $this->newDialog()->setTitle($title)->setShortTitle($short)->appendParagraph($body)->addSubmitButton(pht('Terminate'))->addCancelButton($panel_uri);
 }
開發者ID:pugong,項目名稱:phabricator,代碼行數:39,代碼來源:PhabricatorAuthTerminateSessionController.php

示例9: getOneTimeLoginKeyHash

 /**
  * Hash a one-time login key for storage as a temporary token.
  *
  * @param PhabricatorUser User this key is for.
  * @param PhabricatorUserEmail Optionally, email to verify when
  *  link is used.
  * @param string The one time login key.
  * @return string Hash of the key.
  * task onetime
  */
 private function getOneTimeLoginKeyHash(PhabricatorUser $user, PhabricatorUserEmail $email = null, $key = null)
 {
     $parts = array($key, $user->getAccountSecret());
     if ($email) {
         $parts[] = $email->getVerificationCode();
     }
     return PhabricatorHash::digest(implode(':', $parts));
 }
開發者ID:NeoArmageddon,項目名稱:phabricator,代碼行數:18,代碼來源:PhabricatorAuthSessionEngine.php

示例10: generateToken

 private function generateToken($epoch, $frequency, $key, $len)
 {
     if ($this->getPHID()) {
         $vec = $this->getPHID() . $this->getAccountSecret();
     } else {
         $vec = $this->getAlternateCSRFString();
     }
     if ($this->hasSession()) {
         $vec = $vec . $this->getSession()->getSessionKey();
     }
     $time_block = floor($epoch / $frequency);
     $vec = $vec . $key . $time_block;
     return substr(PhabricatorHash::digest($vec), 0, $len);
 }
開發者ID:sethkontny,項目名稱:phabricator,代碼行數:14,代碼來源:PhabricatorUser.php

示例11: newFromFileData

 public static function newFromFileData($data, array $params = array())
 {
     $selector = PhabricatorEnv::newObjectFromConfig('storage.engine-selector');
     $engines = $selector->selectStorageEngines($data, $params);
     if (!$engines) {
         throw new Exception("No valid storage engines are available!");
     }
     $data_handle = null;
     $engine_identifier = null;
     $exceptions = array();
     foreach ($engines as $engine) {
         $engine_class = get_class($engine);
         try {
             // Perform the actual write.
             $data_handle = $engine->writeFile($data, $params);
             if (!$data_handle || strlen($data_handle) > 255) {
                 // This indicates an improperly implemented storage engine.
                 throw new PhabricatorFileStorageConfigurationException("Storage engine '{$engine_class}' executed writeFile() but did " . "not return a valid handle ('{$data_handle}') to the data: it " . "must be nonempty and no longer than 255 characters.");
             }
             $engine_identifier = $engine->getEngineIdentifier();
             if (!$engine_identifier || strlen($engine_identifier) > 32) {
                 throw new PhabricatorFileStorageConfigurationException("Storage engine '{$engine_class}' returned an improper engine " . "identifier '{$engine_identifier}': it must be nonempty " . "and no longer than 32 characters.");
             }
             // We stored the file somewhere so stop trying to write it to other
             // places.
             break;
         } catch (Exception $ex) {
             if ($ex instanceof PhabricatorFileStorageConfigurationException) {
                 // If an engine is outright misconfigured (or misimplemented), raise
                 // that immediately since it probably needs attention.
                 throw $ex;
             }
             // If an engine doesn't work, keep trying all the other valid engines
             // in case something else works.
             phlog($ex);
             $exceptions[] = $ex;
         }
     }
     if (!$data_handle) {
         throw new PhutilAggregateException("All storage engines failed to write file:", $exceptions);
     }
     $file_name = idx($params, 'name');
     $file_name = self::normalizeFileName($file_name);
     // If for whatever reason, authorPHID isn't passed as a param
     // (always the case with newFromFileDownload()), store a ''
     $authorPHID = idx($params, 'authorPHID');
     $file = new PhabricatorFile();
     $file->setName($file_name);
     $file->setByteSize(strlen($data));
     $file->setAuthorPHID($authorPHID);
     $file->setContentHash(PhabricatorHash::digest($data));
     $file->setStorageEngine($engine_identifier);
     $file->setStorageHandle($data_handle);
     // TODO: This is probably YAGNI, but allows for us to do encryption or
     // compression later if we want.
     $file->setStorageFormat(self::STORAGE_FORMAT_RAW);
     if (isset($params['mime-type'])) {
         $file->setMimeType($params['mime-type']);
     } else {
         $tmp = new TempFile();
         Filesystem::writeFile($tmp, $data);
         $file->setMimeType(Filesystem::getMimeType($tmp));
     }
     $file->save();
     return $file;
 }
開發者ID:ramons03,項目名稱:phabricator,代碼行數:66,代碼來源:PhabricatorFile.php

示例12: calculateEnvironmentHash

 public static function calculateEnvironmentHash()
 {
     $keys = self::getKeysForConsistencyCheck();
     $values = array();
     foreach ($keys as $key) {
         $values[$key] = self::getEnvConfigIfExists($key);
     }
     return PhabricatorHash::digest(json_encode($values));
 }
開發者ID:JohnnyEstilles,項目名稱:phabricator,代碼行數:9,代碼來源:PhabricatorEnv.php

示例13: executeChecks

 protected function executeChecks()
 {
     // NOTE: We've already appended `environment.append-paths`, so we don't
     // need to explicitly check for it.
     $path = getenv('PATH');
     if (!$path) {
         $summary = pht('The environmental variable %s is empty. Phabricator will not ' . 'be able to execute some commands.', '$PATH');
         $message = pht("The environmental variable %s is empty. Phabricator needs to execute " . "some system commands, like `%s`, `%s`, `%s`, and `%s`. To execute " . "these commands, the binaries must be available in the webserver's " . "%s. You can set additional paths in Phabricator configuration.", '$PATH', 'svn', 'git', 'hg', 'diff', '$PATH');
         $this->newIssue('config.environment.append-paths')->setName(pht('%s Not Set', '$PATH'))->setSummary($summary)->setMessage($message)->addPhabricatorConfig('environment.append-paths');
         // Bail on checks below.
         return;
     }
     // Users are remarkably industrious at misconfiguring software. Try to
     // catch mistaken configuration of PATH.
     $path_parts = explode(PATH_SEPARATOR, $path);
     $bad_paths = array();
     foreach ($path_parts as $path_part) {
         if (!strlen($path_part)) {
             continue;
         }
         $message = null;
         $not_exists = false;
         foreach (Filesystem::walkToRoot($path_part) as $part) {
             if (!Filesystem::pathExists($part)) {
                 $not_exists = $part;
                 // Walk up so we can tell if this is a readability issue or not.
                 continue;
             } else {
                 if (!is_dir(Filesystem::resolvePath($part))) {
                     $message = pht("The PATH component '%s' (which resolves as the absolute path " . "'%s') is not usable because '%s' is not a directory.", $path_part, Filesystem::resolvePath($path_part), $part);
                 } else {
                     if (!is_readable($part)) {
                         $message = pht("The PATH component '%s' (which resolves as the absolute path " . "'%s') is not usable because '%s' is not readable.", $path_part, Filesystem::resolvePath($path_part), $part);
                     } else {
                         if ($not_exists) {
                             $message = pht("The PATH component '%s' (which resolves as the absolute path " . "'%s') is not usable because '%s' does not exist.", $path_part, Filesystem::resolvePath($path_part), $not_exists);
                         } else {
                             // Everything seems good.
                             break;
                         }
                     }
                 }
             }
             if ($message !== null) {
                 break;
             }
         }
         if ($message === null) {
             if (!phutil_is_windows() && !@file_exists($path_part . '/.')) {
                 $message = pht("The PATH component '%s' (which resolves as the absolute path " . "'%s') is not usable because it is not traversable (its '%s' " . "permission bit is not set).", $path_part, Filesystem::resolvePath($path_part), '+x');
             }
         }
         if ($message !== null) {
             $bad_paths[$path_part] = $message;
         }
     }
     if ($bad_paths) {
         foreach ($bad_paths as $path_part => $message) {
             $digest = substr(PhabricatorHash::digest($path_part), 0, 8);
             $this->newIssue('config.PATH.' . $digest)->setName(pht('%s Component Unusable', '$PATH'))->setSummary(pht('A component of the configured PATH can not be used by ' . 'the webserver: %s', $path_part))->setMessage(pht("The configured PATH includes a component which is not usable. " . "Phabricator will be unable to find or execute binaries located " . "here:" . "\n\n" . "%s" . "\n\n" . "The user that the webserver runs as must be able to read all " . "the directories in PATH in order to make use of them.", $message))->addPhabricatorConfig('environment.append-paths');
         }
     }
 }
開發者ID:pugong,項目名稱:phabricator,代碼行數:63,代碼來源:PhabricatorPathSetupCheck.php

示例14: getMarkupFieldKey

 public function getMarkupFieldKey($field)
 {
     // We can't use ID because synthetic comments don't have it.
     return 'DI:' . PhabricatorHash::digest($this->getContent());
 }
開發者ID:pugong,項目名稱:phabricator,代碼行數:5,代碼來源:DifferentialInlineComment.php

示例15: getMarkupFieldKey

 public function getMarkupFieldKey($field)
 {
     $hash = PhabricatorHash::digest($this->getMarkupText($field));
     return $this->getPHID() . ':' . $field . ':' . $hash;
 }
開發者ID:fengshao0907,項目名稱:phabricator,代碼行數:5,代碼來源:PhameBlog.php


注:本文中的PhabricatorHash::digest方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。