XF 2.1 UUID/GUID in MySQL?

Jaxel

Well-known member
I'm looking into using unique IDs as a primary key for one of my tables, instead of an auto-increment integer. The reason for this is for obfuscation.

What would be the best way to implement this? MySQL handles generating auto-incremented integers themselves, and XenForo passes it along just fine. Do MySQL or XenForo have build in functions for handing UUID/GUID?
 
There's nothing built into XF for it, but MySQL does have a UUID() function. There's nothing actually built into PHP for generating a UUID either so you would probably need to find a library that does it.

Overall, I'm thinking that UUIDs in the official sense probably aren't necessary.

Often in XF when we need an obfuscated unique identifier, we actually still use an auto increment primary key, but then generate a random string to use as a unique key.

You can see some code we use to generate unique and random purchase request keys in XF\Repository\Purchase::generateRequestKey().

For something a little more aesthetically pleasing, we do this to generate XenForo license keys:
PHP:
$licenseKey = strtoupper(substr(md5(uniqid(microtime())), 0, 10));
That produces something like:
Code:
6CBA61B743

You'll notice that you never see the fact that your XenForo licenses have an integer primary key, because we only ever show you the 10 character upper cased partial MD5 license key.
 
Top Bottom