guidsen/fake-identifier 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

guidsen/fake-identifier

最新稳定版本:v1.0.1

Composer 安装命令:

composer require guidsen/fake-identifier

包简介

A package to protect your ID with some hashing.

README 文档

README

With this little package you are able to transform your internal id's to obfuscated integers easily in Laravel and Lumen 5.1. The package is made on top of jenssegers/optimus and is similar to Hashids.
If you use this library and use the traits that comes with it, you will be able to get a hashed identifier by using the hashed_id attribute. So $model->hashed_id will contain you hashed id.
If you want to change the attribute name, you can have a look at the usage section.

Installation

composer require guidsen/fake-identifier

Setup

The hashing algorithm depends on 3 integers.

  • A large prime number lower than 2147483647
  • The inverse prime so that (PRIME * INVERSE) & MAXID == 1
  • A large random integer lower than 2147483647

You can calculate a prime number yourself, or pick one from this list.
Once you have selected a prime number, you can use the included console command to calculated the inverse prime that is used for the decoding process and generate a random integer:

> php vendor/bin/optimus spark YOUR_PRIME

Prime: 1580030173
Inverse: 59260789
Random: 1163945558

Because the helpers depend on the container binding you will have to bind the instance to the container with the optimus key. This will look like (fill in your the values you just generated):

$this->app->bind('optimus', function () {
    $optimus = new \Guidsen\FakeIdentifier\Optimus(15468539, 1296427827, 340274557);
    return $optimus;
});

Usage

The library comes with two helper traits.
FakeIdentifier: This trait should be used in your model. This will add a attribute containing the hashed id.
FakeIdentifierHelper: This trait should be used in your controllers or base controller. It will contain a encode and decode method which could be usefull.

The attribute which will contain the hashed id, default to hashed_id. You can change this to your own favorite id by using the setAttributeName method on the Optimus instance in the container binding.

$optimus = new \Guidsen\FakeIdentifier\Optimus(15468539, 1296427827, 340274557);
$optimus->setAttributeName('my_hashed_id');

统计信息

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

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2015-06-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固