user32262
user32262

Reputation: 8850

What is the best way to generate unique session IDs?

I want to generate a 16 character alphanumeric Session ID string. What is the best way to do this so that it is guaranteed that the string generated will be unique every time?

Note: I will be using C++ to generate the session IDs.

Upvotes: 3

Views: 6179

Answers (2)

John Saunders
John Saunders

Reputation: 161773

Use a GUID. How you generate one will depend on the platform you're running on.

Upvotes: 0

Greg Hewgill
Greg Hewgill

Reputation: 992975

Typically you would create a GUID using whatever language/OS services provide such a service. Commonly available GUIDs are 16 bytes long, which in hex representation would be 32 characters. You can base64 encode that and get it slightly smaller (22 characters or so). Do you really need exactly 16 characters?

Upvotes: 7

Related Questions