A few days ago received a task, party a previously looking for a product to outsource the purchase of a small station is not ready to continue to outsource maintenance, hands over to us, by the way a bunch of amendments. One of the comments is that the outsourcing of the development of the order site directly with the database to increase the ID as the order number, resulting in the order number is short and good to remember, the next single person directly through the order number can be inferred the sales of the product, for the boast of the party's salesman set a huge obstacle. as expected, the burden arrived on my desk. by searching, I listed several ways for the leader to choose:
METHOD \ Original ID value |
Advantages and Disadvantages |
1 |
5 |
10 |
100 |
Order creation time stamp turn month day seconds after minutes plus left spell 0 ID, length 22 |
Pros: No change to table structure data Cons: A knowledgeable person can see through it at a glance |
2017032110445700000001 |
2017032110445700000005 |
2017032110445700000010 |
2017032110445700000100 |
All IDs plus 41100000, length 8 |
Pros: Short, 8-bit easy to read Cons: Need to alter TABLE data |
41100001 |
41100005 |
41100010 |
41100100 |
Add a field to the order table to generate a given length using a random string |
Pros: The order number is completely unrelated to the ID and it is difficult to determine sales Cons: Need to ALTER TABLE structure |
Random |
Random |
Random |
Random |
Using the GitHub plugin, Optimus |
Pros: No change to table structure data |
647890742 |
443442450 |
191221 |
1452509963 |
According to the instructions, it seems that the decision to use Optimus, search on GitHub, the first one is. first set up a test environment locally, using composer to pull down the source code, in the own bin directory to run
PHP Optimus Spark
get three configuration required parametersprime:2147483647 One of the larger primesInverse: An inverse prime, so (prime * inverse) & 2147483647 = = 1Random: An arbitrary number below 2147483647build a test file and set the parameters to work.
UseJenssegers\optimus\optimus;//set the path correctly based on the location where the test files and vendor are locatedrequire_once(__dir__. ' /.. /vendor/autoload.php ');$config=Array( ' Prime ' =>653936159, ' inverse ' =>7845343, ' random ' =>421554952);$optimus=NewOptimus ($config[' Prime '],$config[' Inverse '],$config[' Random ']);$exampleId=Rand(1,99999);$encode=$optimus->encode ($exampleId);$decode=$optimus->decode ($encode);Echo"raw:{$exampleId}<br>encode:{$encode}<br>decode:{$decode}";
the obfuscation algorithm uses the integer hash of the Donald Knuth, with the specific calculation:ENCODE = (RAW * PRIME) & (2^32-1) ^ RANDOMDECODE = ((ENCODE ^ RANDOM) * Inverse) & (2^32-1)(PRIME * inverse) & (2^32-1) = 1 The disadvantage is that if the order is printed into paper, then three parameters must be fixed and can no longer be transformed.
Share a handy php under ID obfuscation plugin