Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Parts of GUID as ID

I'm developing an ASP .Net MVC application. One of my actions requires id as a parameter. For example:

public actionresult Detail(Guid id){
    return View();
}

As you can see, I'm using Guid instead of Int. The issue is more cosmetic. The url can be very long, such as localhost/Detail/0c157b42-379d-41d5-b9ba-83e9df9985b2.

Is it safe to take only parts of the Guid like localhost/Detail/0c157b42?

like image 610
dritterweg Avatar asked Nov 26 '09 06:11

dritterweg


People also ask

Is GUID the same as ID?

A GUID (globally unique identifier) is a 128-bit text string that represents an identification (ID). Organizations generate GUIDs when a unique reference number is needed to identify information on a computer or network. A GUID can be used to ID hardware, software, accounts, documents and other items.

Can 2 GUIDs be the same?

While each generated GUID is not guaranteed to be unique, the total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is very small.

What is the rule of GUID?

The valid format for a GUID is {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} where X is a hex digit (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F). Note that utilities such as GUIDGEN can generate GUIDs containing lowercase letters.


2 Answers

GUID is designed in such a way that it is intended to be unique, but any part of it is not. See this blog post for details. If you need to shorten the GUID take a good hash of it - like SHA-1 or (if you don't have security concerns) MD5.

like image 106
sharptooth Avatar answered Sep 17 '22 22:09

sharptooth


No, it's not safe.

You can calculate a SHA-2 hash of it though, and take the first few characters of that.

like image 23
Noon Silk Avatar answered Sep 21 '22 22:09

Noon Silk