Create unique GUIDs - need help
Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=26090
Printed Date: 29 March 2026 at 9:21am Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com
Topic: Create unique GUIDs - need help
Posted By: StarDust
Subject: Create unique GUIDs - need help
Date Posted: 11 August 2008 at 2:57am
I want to create unique IDs for my members which will be 6 chars long and will be prefixed by alphabets.
Example: ft8795
Does anyone know which is the better way to do this?
------------- http://board.ebizbd.net/"> Tips, mods and skins for WWF v9.x
|
Replies:
Posted By: Jono
Date Posted: 11 August 2008 at 7:35pm
|
Hi StarDust,
Is it completly random or the next in a sequence? (i.e. aa0000, aa0001, etc.) Either way, I suspect you'd need to generate an ID and then query the database to make sure it's not in use. It's possible to do this in a stored procedure if you're using MS SQL.
It is for use in WWF or a different application?
Jono
|
Posted By: StarDust
Date Posted: 12 August 2008 at 1:44am
Thank you Jono for replying.
Actually I have little knowledge in this part.
I learned that using Server.CreateObject("Scriptlet.TypeLib") or stored procedures I can create GUIDs. I found couple of other functions that says that generate GUIDs. But my problem is I never worked with GUIDs.
Actually I need unique IDs for couple of things. Currently I am working on a system that requires unique order ids, receipt ids, event ids and member ids. My problem is I cannot just generate integer autonumbers and assign them as IDs - like the author_ID in WWF. I need strings prefixed by alphabets. And I do not know which way to go.
Another thing I am considering is a GUID string is not short in length. If a shorter length unique IDs can be created, say 6 to 10 chars long, it will be better - or is it impossible? But I cannot just depend on the system timer and create simple IDs because I cannot take the risk to generate duplicate values.
It is new to me and I am confused what to follow.
It is not for WWF and I plan to script the whole application in Access and then port it to MS SQL.
------------- http://board.ebizbd.net/"> Tips, mods and skins for WWF v9.x
|
Posted By: StarDust
Date Posted: 12 August 2008 at 1:46am
Access for testing and MS SQL in the development.
------------- http://board.ebizbd.net/"> Tips, mods and skins for WWF v9.x
|
Posted By: StarDust
Date Posted: 12 August 2008 at 1:50am
Ow, missed again, sorry.
I guess a sequential unique ID could be a security risk because anyone can guess what's after or before the sequence.
Jono wrote:
Either way, I suspect you'd need to generate an ID and then query the database to make sure it's not in use. |
But this way, there might be loops and the database will be huge after 1 year of use. The whole thing is a business application. So, querying the database can be a performance issue. Note, I have to generate unique Ids not only for my members but there are other Ids also.
------------- http://board.ebizbd.net/"> Tips, mods and skins for WWF v9.x
|
Posted By: Jono
Date Posted: 12 August 2008 at 7:20pm
|
Have you considered using the "autonumber" feature of the database and then prefixing an identifier infront of it? For example each invoice would have a unique ID in the database, but when it's printed (screen or paper), you could append INV and leading zero's: e.g. INV000023 - this eliminates the requirement to check for a unique ID.
You may also want to look at SQL Express - it's free and ideal for a development environment and without the need to modify code from Access to SQL Server.
I appreciate what you're saying about guessing ID's in a sequence, but it's bad to have "security by obsecurity" - if someone, for example, want's to view an invoice, it should either be their invoice or they should be a sys admin, otherwise they should be directed to another page.
GUID's are special type of ID's and, as you've guessed, not exactly what you're after.
I hope the above helps, but let me know if i can clarify anything for you.
|
Posted By: StarDust
Date Posted: 12 August 2008 at 7:42pm
Jono, thanks for your reply.
Jono wrote:
....if someone, for example, want's to view an invoice, it should either be their invoice |
Right Jono. But it's not about viewing an invoice or order, actually there are other issues. I do not want someone guess an order number or a support ticket number or a reference number. Because some numbers(like orders and references) will be used in some hard copied docs of the company. And if someone can guess those numbers, he might be able to guess some information even have access to some information phisically or ver the phone that the company might not want to expose. And if it happens somehow, ultimately the headache will come on to me. Look we all know business men are not that much IT aware. So, it is pretty possible getting more information from a normal staff by only providing an order number and the reference number to that order. So I need those as non sequential.
Jono wrote:
GUID's are special type of ID's and, as you've guessed, not exactly what you're after |
So, are you trying to say that I can generate unique IDs without creating a GUID? How? Consider there will be performance issues.
Or, if it is impossible to generate unique IDs, is there a way to shorten the lenghth of a GUID? like, converting the GUID or some part of it to another value?
Your suggestion do helps me undertand where i am. Thank you very much for helping me through this and I look forward to get some more till I get a solution from you!
------------- http://board.ebizbd.net/"> Tips, mods and skins for WWF v9.x
|
Posted By: dj air
Date Posted: 13 August 2008 at 8:41pm
|
hi,
i see what you want regarding security , you can use prefixes and hex values and timers
INV-AccID-RANDOMNumber(5)
and using a MOD 2 = 0 function within the random number function. using your Acc to randoimise the sections being used like SECOND(NOW()), and Value = round(odd/Second)
and depending on that use different MOD 3 = 3 or others to create random
and place into a DB
just a few ideas , simular with my security measures i use in my Apps (require to be secure)
|
Posted By: StarDust
Date Posted: 14 August 2008 at 6:14am
dj air wrote:
randoimise the sections being used like SECOND(NOW()), and Value = round(odd/Second)
and depending on that use different MOD 3 = 3 or others to create random |
This way the whole ID will be unique, right? Or am I required to run a check?
------------- http://board.ebizbd.net/"> Tips, mods and skins for WWF v9.x
|
Posted By: dj air
Date Posted: 14 August 2008 at 8:39am
|
it will be random,
thinking on making it unique , most ways will require a DB check, because any check may result in an other record.
its making enough veriables time is usually a good start point to make it random.
|
Posted By: Jono
Date Posted: 16 August 2008 at 5:21pm
StarDust wrote:
Jono wrote:
GUID's are special type of ID's and, as you've guessed, not exactly what you're after |
So, are you trying to say that I can generate unique IDs without creating a GUID? How? Consider there will be performance issues.
Or, if it is impossible to generate unique IDs, is there a way to shorten the lenghth of a GUID? like, converting the GUID or some part of it to another value?
Your suggestion do helps me undertand where i am. Thank you very much for helping me through this and I look forward to get some more till I get a solution from you!
|
Hi Stardust,
I understand a bit better what you're trying to achieve. So let's make it a bit simpler for ourselves. As DJ's said, you can create your own Unique ID's, but you'll have to check them. Autonumbers are already checked, but they are squential, and not what you're after.
So, were back on to GUID's - yes, i know this is where you started, sorry about that.
I'm going to assume you're going to use SQL2005 (in one version or another) rather than writing two versions of your code. Here are some links about generating GUIDs:
http://www.sqlservercurry.com/2007/12/generate-unique-number-in-sql-server.html - http://www.sqlservercurry.com/2007/12/generate-unique-number-in-sql-server.html
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=104575 - http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=104575
and finally WIKI ('cos it's always correct  ): http://en.wikipedia.org/wiki/Globally_Unique_Identifier - http://en.wikipedia.org/wiki/Globally_Unique_Identifier
The first link also shows some conversion options. Because the number is autogenerated, it's a 32 byte number and (i believe) the length cannot be changed. If you do want to represent it in a shorter fashion, you could try writing a routing to change the base.
For example hex is base 16 (0-9,A-F), but you could use base 36(0-9,A-Z) or some other base [base62 - 0-9,A-Z,a-z - this get more complicated!]. I did write a converter in Pascal as a college project, but that was ages ago!
I think the NEWID() function is the way forward for you, but let us know what you think.
Jono
|
Posted By: Dan H
Date Posted: 29 August 2008 at 8:58pm
|
Could it be as simple as grabbing the autonumber, and then stringing it with an alpha and a random? That way, even if the random came up twice- the autonumber would keep it unique.
|
|