Is it possible to include UUID in shortcode? (use only the first 8 characters)

We use the UUID for our primary keys in our db (generated php stored in mysql). The problem is that when someone wants to edit something or view their profile, they have this huge, scary, ugly uuid line at the end of the URL. (Change? ID = .....)

Would it be safe (read: still unique) if we used only the first 8 characters, all before the first hyphen?

If this is NOT safe, is there a way to translate it to something even shorter for use in a URL that could be converted back to hex to use it as a search? I know that I can base64 encode it to reduce it to 22 characters, but is there something even shorter?

EDIT I โ€‹โ€‹read this question and he said he uses base64. again, is anything shorter?

+4
source share
5 answers

Reducing the UUID increases the likelihood of a collision. You can do it, but it's a bad idea. Using only 8 characters means only 4 bytes of data, so you are expecting a collision if you have about 2 ^ 16 identifiers - far from ideal.

Your best option is to take the raw UUID bytes (rather than the hexadecimal representation) and encode it with base64. Or just donโ€™t worry, because I seriously doubt that your users care about that in the URL.

+5
source

Do not cut one bit from this UUID: you do not have control over the algorithm that created it, there are several possible implementations, the implementation of the algorithm can be changed (example: changed with the PHP version, you are using)

If you ask me that the UUID in the address bar does not look intimidating or complicated, even a simple Google search for โ€œUUIDโ€ creates the worst URLs and everyone is used to looking at google URLs!

If you want more attractive URLs, take a look at the address bar of this stackoverflow.com article. They use the article id followed by the title of the question. Only the identification part is important, everything else is there to make eyes easier for readers (try and try, you can delete something after the ID, you can replace it with junk - it doesnโ€™t matter).

+3
source

It is unsafe to crop uuid. In addition, they are designed to be unique throughout the world, so you will not be able to reduce them. It is best to either assign a unique number to each user, or allow users to select a user (unique) line (for example, username or alias) that can be decrypted. So you could edit? Id = .... or edit? Name = blah, and then decode the name in uuid in the script.

+1
source

If you are worried about scaring users with a UUID in the URL, why not write it in a hidden form field?

+1
source

It depends on how you create the UUID - if you use PHP uniqid , then these are the right-most digits that are more "unique". However, if you are going to crop the data, then there is no real guarantee that it will be unique in any case.

Regardless, I would say that this is a somewhat suboptimal approach - can't you use a unique (and ideally significant) text link string instead of an ID in the query string? (It is difficult to find out without knowing about the problem area, but, in my opinion, this is always the best approach, even if SEO, etc. It is not a factor.)

If you use this approach, you can also allow MySQL to generate unique identifiers, which is probably significantly more sensible than trying to handle this in PHP.

0
source

Source: https://habr.com/ru/post/1333805/


All Articles