Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/util/password/PhabricatorPasswordHasher.php
| Show First 20 Lines • Show All 207 Lines • ▼ Show 20 Lines | /* -( Using Hashers )------------------------------------------------------ */ | ||||
| * Get all available password hashers. This may include hashers which can not | * Get all available password hashers. This may include hashers which can not | ||||
| * actually be used (for example, a required extension is missing). | * actually be used (for example, a required extension is missing). | ||||
| * | * | ||||
| * @return list<PhabicatorPasswordHasher> Hasher objects. | * @return list<PhabicatorPasswordHasher> Hasher objects. | ||||
| * @task hashing | * @task hashing | ||||
| */ | */ | ||||
| public static function getAllHashers() { | public static function getAllHashers() { | ||||
| $objects = id(new PhutilSymbolLoader()) | $objects = id(new PhutilSymbolLoader()) | ||||
| ->setAncestorClass('PhabricatorPasswordHasher') | ->setAncestorClass(__CLASS__) | ||||
| ->loadObjects(); | ->loadObjects(); | ||||
| $map = array(); | $map = array(); | ||||
| foreach ($objects as $object) { | foreach ($objects as $object) { | ||||
| $name = $object->getHashName(); | $name = $object->getHashName(); | ||||
| $potential_length = strlen($name) + $object->getHashLength() + 1; | $potential_length = strlen($name) + $object->getHashLength() + 1; | ||||
| $maximum_length = self::MAXIMUM_STORAGE_SIZE; | $maximum_length = self::MAXIMUM_STORAGE_SIZE; | ||||
| ▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | /* -( Using Hashers )------------------------------------------------------ */ | ||||
| */ | */ | ||||
| public static function getCurrentAlgorithmName(PhutilOpaqueEnvelope $hash) { | public static function getCurrentAlgorithmName(PhutilOpaqueEnvelope $hash) { | ||||
| $raw_hash = $hash->openEnvelope(); | $raw_hash = $hash->openEnvelope(); | ||||
| if (!strlen($raw_hash)) { | if (!strlen($raw_hash)) { | ||||
| return pht('None'); | return pht('None'); | ||||
| } | } | ||||
| try { | try { | ||||
| $current_hasher = PhabricatorPasswordHasher::getHasherForHash($hash); | $current_hasher = self::getHasherForHash($hash); | ||||
| return $current_hasher->getHumanReadableName(); | return $current_hasher->getHumanReadableName(); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $info = self::parseHashFromStorage($hash); | $info = self::parseHashFromStorage($hash); | ||||
| $name = $info['name']; | $name = $info['name']; | ||||
| return pht('Unknown ("%s")', $name); | return pht('Unknown ("%s")', $name); | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the human-readable algorithm name for the best available hash. | * Get the human-readable algorithm name for the best available hash. | ||||
| * | * | ||||
| * @return string Human-readable name for best hash. | * @return string Human-readable name for best hash. | ||||
| */ | */ | ||||
| public static function getBestAlgorithmName() { | public static function getBestAlgorithmName() { | ||||
| try { | try { | ||||
| $best_hasher = PhabricatorPasswordHasher::getBestHasher(); | $best_hasher = self::getBestHasher(); | ||||
| return $best_hasher->getHumanReadableName(); | return $best_hasher->getHumanReadableName(); | ||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| return pht('Unknown'); | return pht('Unknown'); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||