2017 © Pedro Peláez
 

library ids

Short, obfuscated and efficient IDs for PHP

image

delight-im/ids

Short, obfuscated and efficient IDs for PHP

  • Saturday, July 8, 2017
  • by delight-im
  • Repository
  • 3 Watchers
  • 9 Stars
  • 895 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

PHP-IDs

Short, obfuscated and efficient IDs for PHP, (*1)

No database changes are required. The original (integer) IDs are all you need., (*2)

No collisions. Reversible., (*3)

Why do I need this?

  • Don't leak information to your competitors (e.g. number of orders, sign-ups per day)
  • Prevent resource enumeration by waiving sequential IDs
  • Mix up IDs a little bit in order to make guessing them harder
  • ~~Security through obscurity~~

Requirements

  • PHP 5.6.0+
    • GMP extension

Installation

  1. Include the library via Composer [?]:, (*4)

    $ composer require delight-im/ids
    
  2. Include the Composer autoloader:, (*5)

    require __DIR__ . '/vendor/autoload.php';
    

Usage

Creating an instance

$generator = new \Delight\Ids\Id();

Encoding and decoding IDs

$generator->encode(6); // => "43Vht7"
$generator->decode('43Vht7'); // => 6

Shortening a number without obfuscating it

$generator->shorten(3141592); // => "vJST"
$generator->unshorten("vJST"); // => 3141592

Obfuscating a number without shortening it

$generator->obfuscate(42); // => 958870139
$generator->deobfuscate(958870139); // => 42

Customization

  1. Shuffle the characters of the alphabet that is used for the base conversion. Calling \Delight\Ids\Id::createRandomAlphabet() may be helpful for that purpose. You might also change the alphabet entirely, but there's usually no need to do that.
  2. Pass your new alphabet to the constructor as the first argument.
  3. Clone this repository and then execute the file tests/index.php to generate your custom prime number, inverse prime and random number for Knuth's multiplicative hashing.
  4. Pass your three new numbers to the constructor as the second, third and fourth argument, respectively.

Contributing

All contributions are welcome! If you wish to contribute, please create an issue first so that your feature, problem or question can be discussed., (*6)

License

This project is licensed under the terms of the MIT License., (*7)

The Versions

08/07 2017

dev-master

9999999-dev https://github.com/delight-im/PHP-IDs

Short, obfuscated and efficient IDs for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

id shorten hash encode decode ids hashids obfuscate hashid obfuscation

10/09 2016

v1.0.1

1.0.1.0 https://github.com/delight-im/PHP-IDs

Short, obfuscated and efficient IDs for PHP

  Sources   Download

MIT

The Requires

 

The Development Requires

id shorten hash encode decode ids hashids obfuscate hashid obfuscation

08/09 2016

v1.0.0

1.0.0.0 https://github.com/delight-im/PHP-IDs

Short, obfuscated and efficient IDs for PHP

  Sources   Download

MIT

The Requires

 

id shorten hash encode decode ids hashids obfuscate hashid obfuscation