承接 delight-im/ids 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

delight-im/ids

最新稳定版本:v1.0.1

Composer 安装命令:

composer require delight-im/ids

包简介

Short, obfuscated and efficient IDs for PHP

README 文档

README

Short, obfuscated and efficient IDs for PHP

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

No collisions. Reversible.

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 [?]:

    $ composer require delight-im/ids
    
  2. Include the Composer autoloader:

    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.

License

This project is licensed under the terms of the MIT License.

统计信息

  • 总下载量: 9.03k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 29
  • 点击次数: 0
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 28
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-09-08