public function testHasherSyntax() { $caught = null; try { PhabricatorPasswordHasher::getHasherForHash(new PhutilOpaqueEnvelope('xxx')); } catch (Exception $ex) { $caught = $ex; } $this->assertTrue($caught instanceof Exception, pht('Exception on unparseable hash format.')); $caught = null; try { PhabricatorPasswordHasher::getHasherForHash(new PhutilOpaqueEnvelope('__test__:yyy')); } catch (Exception $ex) { $caught = $ex; } $this->assertTrue($caught instanceof PhabricatorPasswordHasherUnavailableException, pht('Fictional hasher unavailable.')); }
/** * Get the human-readable algorithm name for a given hash. * * @param PhutilOpaqueEnvelope Storage hash. * @return string Human-readable algorithm name. */ public static function getCurrentAlgorithmName(PhutilOpaqueEnvelope $hash) { $raw_hash = $hash->openEnvelope(); if (!strlen($raw_hash)) { return pht('None'); } try { $current_hasher = PhabricatorPasswordHasher::getHasherForHash($hash); return $current_hasher->getHumanReadableName(); } catch (Exception $ex) { $info = self::parseHashFromStorage($hash); $name = $info['name']; return pht('Unknown ("%s")', $name); } }