Question

I generate keys for my software as:

Guid.NewGuid().ToString();

that returns something like: 15c6bd70-8d3c-42d0-bb24-40da6e08ed9d

anyways everytime someone purchases a new software I generate a new key. can it be possible that I generate the same key twice? Everytime someone purchase the software I call the method: Guid.NewGuid().ToString() Should I append a counter at the end of each guid to be 100% sure that there cannot be duplicates?

Edit

A constructor of the Guid class takes a byte array of 16 bytes as a parameter. If you serialize the current date (8 bytes) then append another 8 random bytes to the constructor of the GUID will that be 100% secure? I am just asking for learning based on your answers I will probably just have Guid.NewGuid()

Was it helpful?

Solution

An excerpt from one of the best blog series ever written about the Guid:

There are a number of possible strategies for making a unique GUID, and in fact information about the strategy used is encoded in the first four bits of the third "group"; almost every GUID you see will be of the form {xxxxxxxx-xxxx-1xxx-xxxx-xxxxxxxxxxxx} or {xxxxxxxx-xxxx-4xxx-xxxx-xxxxxxxxxxxx}.

If there is a one in that place then the algorithm used to guarantee uniqueness is essentially a variation on the ISBN strategy. The GUID is guaranteed to be unique "in space" by choosing some of the bits as the MAC address of the network card in the machine. (The tricky problem of ensuring that no two network cards in the world have the same MAC address is solved somehow by someone else; how that problem is solved, we don't particularly care. The cost of solving that problem is passed on to you, the consumer, in the purchase cost of the network card.)

In short, it's very unlikely that they would ever collide.

OTHER TIPS

Yes, it's possible, but extremely unlikely. The probability for a GUID collision is about as likely as a bit in the GUID changing spontaneously in memory, and that kind of thing is not something that you normally worry about.

You can already be 100% sure, that is of course if you dont mean that you need to be 100.000000000000000000000000000000000000% sure.

Just use the Guid.. no need to append anything. Unless you expect to sell more copies than there are atoms in the universe (unlikely).

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