Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Hashids and Perceptual hashes

Hashids and Perceptual hashes

PHP Ghent presentation

Jens Segers

April 29, 2015
Tweet

More Decks by Jens Segers

Other Decks in Technology

Transcript

  1. Why id obfuscation? Hiding application internals Reduces chance for URL

    guessing Hide number of users, articles, … More difficult for scrapers
  2. Encoding ids $hashids = new Hashids\Hashids('salt'); $encodedId = $hashids->encode(123); $hashids

    = new Hashids\Hashids('salt'); $decodedId = $hashids->decode('Mj3')[0]; Decoding ids
  3. Calculating the hash Using a different implementation: use Jenssegers\ImageHash\ImageHash; $hasher

    = new ImageHash; $hash = $hasher->hash('path/to/image.jpg'); use Jenssegers\ImageHash\Implementation\AverageHash; $hasher = new ImageHash(new AverageHash); $hash = $hasher->hash('path/to/image.jpg');
  4. Comparing hashes Or use your database: $d = $hasher->compare('image1.jpg', 'image2.jpg');

    $d = $hasher->distance($hash1, $hash2); SELECT BIT_COUNT(hash ^ :hash) as hamming_distance FROM images HAVING hamming_distance < 5