opensourcerefinery / random-string-generator
Random String Generator to make simple tokens
Requires
- php: >=7.1
Requires (Dev)
- phpunit/phpunit: ^7.0
- squizlabs/php_codesniffer: ^3.4
- webmozart/assert: ^1.7
This package is auto-updated.
Last update: 2024-11-23 09:37:32 UTC
README
UUID are great. But should never be public. Auto increment is dead. But how do you share something to the web thats not crazy long (sorry uuid, you nuts) but also not a just a timestamp that on a large system be known to collide.
Well you generate a token / "hash" / random string and use that as something that is unique to link to the entity you want to find.
$generator = new StringOfFormat(4, 'ab');
$this->assertRegExp('/[ab]{4}/', $generator->generate());
$string = RandomStringGenerator::randomString(16);
echo $string;
// vuHlvV9NTCwBbIxa
Pulled from, Citations (and Thanks to):
https://stackoverflow.com/questions/1846202/php-how-to-generate-a-random-unique-alphanumeric-string https://stackoverflow.com/questions/7493102/how-to-output-in-cli-during-execution-of-php-unit-tests https://gnugat.github.io/2018/06/15/short-identifier.html
- 6 first characters: covers 16 777 216 hashes, but first collision happens after 4 096 hashes generated
- 7 first charecters: covers 268 435 456 hashes, but first collision happens after 16 384 hashes generated
- 8 first characters: covers 4 294 967 296 hashes, but first collision happens after 65 536 hashes generated
Research:
Tools:
source-foundry/font-v#2 https://emn178.github.io/online-tools/shake_256.html http://www.getsolid.io/blog/birthday-paradox-coding-solid/ https://blog.codinghorror.com/url-shortening-hashes-in-practice/ https://medium.com/ingeniouslysimple/why-did-we-shift-away-from-database-generated-ids-7e0e54a49bb3