SnapchatAgent::hash PHP Method

hash() public method

Implementation of Snapchat's hashing algorithm.
public hash ( string $first, string $second ) : string
$first string The first value to use in the hash.
$second string The second value to use in the hash.
return string The generated hash.
    public function hash($first, $second)
    {
        // Append the secret to the values.
        $first = self::SECRET . $first;
        $second = $second . self::SECRET;
        // Hash the values.
        $hash = hash_init('sha256');
        hash_update($hash, $first);
        $hash1 = hash_final($hash);
        $hash = hash_init('sha256');
        hash_update($hash, $second);
        $hash2 = hash_final($hash);
        // Create a new hash with pieces of the two we just made.
        $result = '';
        for ($i = 0; $i < strlen(self::HASH_PATTERN); $i++) {
            $result .= substr(self::HASH_PATTERN, $i, 1) ? $hash2[$i] : $hash1[$i];
        }
        return $result;
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Verifies phone number.
  *
  * @param string $code
  *   Code sent for verification by Snapchat.
  *
  */
 public function verifyPhoneNumber($code)
 {
     $timestamp = parent::timestamp();
     $req_token = parent::hash(parent::STATIC_TOKEN, $timestamp);
     $result = parent::post("/bq/phone_verify", array("timestamp" => $timestamp, "action" => "verifyPhoneNumber", "username" => $this->username, "code" => $code), array($req_token, $timestamp), $multipart = false, $debug = $this->debug);
     $result = $result["data"];
     return isset($result->logged) && $result->logged;
 }