Piwik\Common::hash PHP Méthode

hash() public static méthode

Configurable hash() algorithm (defaults to md5)
public static hash ( string $str, boolean $raw_output = false ) : string
$str string String to be hashed
$raw_output boolean
Résultat string Hash string
    public static function hash($str, $raw_output = false)
    {
        static $hashAlgorithm = null;
        if (is_null($hashAlgorithm)) {
            $hashAlgorithm = @Config::getInstance()->General['hash_algorithm'];
        }
        if ($hashAlgorithm) {
            $hash = @hash($hashAlgorithm, $str, $raw_output);
            if ($hash !== false) {
                return $hash;
            }
        }
        return md5($str, $raw_output);
    }

Usage Example

Exemple #1
0
 /**
  * Generate hash on user info and password
  *
  * @param string $userInfo User name, email, etc
  * @param string $password
  * @return string
  */
 private function generateHash($userInfo, $password)
 {
     // mitigate rainbow table attack
     $passwordLen = strlen($password) / 2;
     $hash = Common::hash($userInfo . substr($password, 0, $passwordLen) . SettingsPiwik::getSalt() . substr($password, $passwordLen));
     return $hash;
 }
All Usage Examples Of Piwik\Common::hash