Question

I just came accross this blog which uses ShortGuid to create registration validation tokens.

When i tried to open the link which said A shorter and URL friendly Guid it seems that the link redirects to some other link. It opens some other language site.

But I have few questions, How can a shorter Guid be user friendly? And when should I use it?

Was it helpful?

Solution

There is a copy/past benefit as well. If i understand correctly, it is not about nice URLs, but about validation tokens. A lot of people copy/pase codes by double clicking, and then the Sguid (ShortGuid) is indeed more user friendly. Try it:

Xy0MVKupFES9NpmZ9TiHcw

540c2d5f-a9ab-4414-bd36-9999f5388773

OTHER TIPS

How can a shorter Guid be user friendly?

If your users type in URLs by hand instead of clicking links, so not very likely.

And when should I use it?

All characters in a GUID (A-F, 0-9, -) are URL-safe, so 'safety' isn't really an argument.

You may want to consider it for aesthetical reasons, or for ease of copy-pasting the URL.

Guid's are generally expressed in base-16 (using 0-9 and A-F). This makes the strings long. The same amount of data can be expressed in a shorter string if you use more characters (0-9, a-z, A-Z, and other special characters like _ or @).

While they dont make a difference to your code at all, long GUIDs are ugly looking to have in URLs or anything a user might see so you can convert them to a shorter format that is still not very pretty but takes up less space.

Somebody might argue that the shorter format requires less bandwidth but the practical savings are negligible.

How can a shorter Guid be user friendly?

You answered your own question, in the question. It's pretty obvious: 7A9D35A3 (shorter) is much easier to remember/type than 7A9D35A3-4999-4130-8E2B-EB0447D942FA.

And when should I use it?

An example would be to use it as a reference. Some examples:

  • "An error has occurred, please contact support. Reference: 7A9D35A3"
  • "Your booking was confirmed! Booking code: 7A9D35A3"

What about using a db table to map ID with GUID. Something like

ID      GUID
1000    540c2d5f-a9ab-4414-bd36-9999f5388773
1001    123c2d5f-a9ab-4414-bd36-9999f5388773
1002    567c2d5f-a9ab-4414-bd36-9999f5388773

It would be much easier to scale or migrate then using ID in each db table, and you end up with a clean ID.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top