Generate random string

R

Rob Meade

Hi all,

I need to be able to create some license keys for an application. Ideally
these wouldn't be too long in length (ie, easier to remember/type in), but I
would like them to be auto generated and a check made to see whether or not
that key has already been used, something which could generate up to about
10000 keys (or more if the string doesnt have to be too long) would be very
useful.

A combination of letters, numbers, upper and lower case is needed.

I could sit here and start plugging away at this, an array for numbers, an
array for letters, a random test for uppercase/lowercase etc, but it occured
to me that I'm probably just reinventing the wheel a bit here, someone must
have done this before!

Has anyone produced anything similar to this in the past?

Any help would be appreciated.

Regards

Rob
 
D

Dave Anderson

Rob said:
I need to be able to create some license keys for an application.
Ideally these wouldn't be too long in length (ie, easier to
remember/type in), but I would like them to be auto generated and a
check made to see whether or not that key has already been used,
something which could generate up to about 10000 keys (or more if the
string doesnt have to be too long) would be very useful.

A combination of letters, numbers, upper and lower case is needed.

I could sit here and start plugging away at this, an array for
numbers, an array for letters, a random test for uppercase/lowercase
etc, but it occured to me that I'm probably just reinventing the
wheel a bit here, someone must have done this before!

Has anyone produced anything similar to this in the past?

This will do far more than 10,000, and will give you uniqueness:

GUID = Server.CreateObject("Scriptlet.Typelib").GUID




--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Rob Meade

Thanks chaps, but how will it know its 'unique'? ie, how will it remember
that it hasnt already used that one? I'll try the code in a minute or two -
but if you happen to reply prior to that - how many characters does this
generate by the way?

Thanks again,

Rob
 
R

Rob Meade

(I hate ctrl+enter!!)...

I got this...

FFDA9960-8C53-497F-9D8F-A736352F21C0

That and a password is what a user will need to enter when logging into a
members area to download any updates to an application - bit long - hard to
remember etc...(great for uniqueness mind!)...

Thoughts/suggestions...

Rob
 
A

Aaron [SQL Server MVP]

Well, GUID stands for Globally Unique IDentifier, so you can do the math
from there...

Keep this in mind, of course, if you are going to generate or response.write
from ASP:
http://www.aspfaq.com/2358
 
A

Aaron [SQL Server MVP]

Why does a serial # have to be easy to remember? Do you remember your
Windows product key, your Photoshop serial number, hell your credit card
number?

If you want something easy to remember, then toss this random string
generation out the window, and make users choose their own password!
 
R

Rob Meade

...
Why does a serial # have to be easy to remember?

Because they'll be using it often for logging in purposes, hence in my first
post suggesting that it didnt have too many characters.
Do you remember your Windows product key, your Photoshop serial number,

Absolutely not - agree fully with you there, but I dont need to enter those
every time I want to download a patch/fix etc..
hell your credit card number?

That one I do know - but my card kinda glows red so its easy to see :eek:)
If you want something easy to remember, then toss this random string
generation out the window, and make users choose their own password!

They'll have a password as well as the key Aaron, the licence number I guess
is affectively their username.

Regards

Rob
 
A

Aaron [SQL Server MVP]

They'll have a password as well as the key Aaron, the licence number I
guess
is affectively their username.

Then I suggest using their e-mail address as the username (which is actually
quite common). *Anything* you generate for them is going to be another
hard-to-remember string that they're going to write on a sticky, forget,
etc.

A
 
R

Rob Meade

...
Well, GUID stands for Globally Unique IDentifier, so you can do the math
from there...

Whilst not really wanting to go down this road, but feeling propelled to say
it....there must be an upper limit to the number of combinations though
surely - if I do the response.write GUID for example and then held F5 down
on my PC lets say for the rest of my life time I'm surely going to get a
duplicate eventually???

I'm unaware (and you might have to excuse my ignorance a little as Maths was
never a strong subject for me) - of anything thats simply endless - apart
from space - but even that must have boundaries somewhere...(wooow - brain
is starting to melt a bit now)..
Keep this in mind, of course, if you are going to generate or response.write
from ASP:
http://www.aspfaq.com/2358

Thanks for that, I didnt even know about the GUID ability in ASP so I've
learnt something new tonight :eek:)

Rob
 
A

Aaron [SQL Server MVP]

The number of combinations is 36 ^ 32. Think about this for a second... 36
^ 6 exceeds the upper boundary for an INT datatype (~2 billion). 36 ^ 13
exceeds the upper boundary for a BIGINT datatype
(9,223,372,036,854,775,807). So take that latter number, square it, and
then multiply that by 2 billion.

This is no RAND(), trust me.
 
E

Evertjan.

Aaron [SQL Server MVP] wrote on 09 jun 2004 in
microsoft.public.inetserver.asp.general:
The number of combinations is 36 ^ 32. Think about this for a
second... 36 ^ 6 exceeds the upper boundary for an INT datatype (~2
billion). 36 ^ 13 exceeds the upper boundary for a BIGINT datatype
(9,223,372,036,854,775,807). So take that latter number, square it,
and then multiply that by 2 billion.

This is no RAND(), trust me.

rant() perhaps?

Main Entry: rant
Pronunciation: 'rant
Function: verb
Etymology: obsolete Dutch ranten, randen
intransitive senses
1 : to talk in a noisy, excited, or declamatory manner
2 : to scold vehemently
transitive senses : to utter in a bombastic declamatory fashion

================

But then, Aaron, we trust you.
 
A

Aaron [SQL Server MVP]

1 : to talk in a noisy, excited, or declamatory manner
2 : to scold vehemently
transitive senses : to utter in a bombastic declamatory fashion

================

But then, Aaron, we trust you.

I don't think I have submitted examples of either 1. or 2. in this thread.
It's pretty simple math, really.

A
 
D

Dave Anderson

Aaron said:
The number of combinations is 36 ^ 32. Think about this for a
second... 36 ^ 6 exceeds the upper boundary for an INT datatype (~2
billion). 36 ^ 13 exceeds the upper boundary for a BIGINT datatype
(9,223,372,036,854,775,807). So take that latter number, square it,
and then multiply that by 2 billion.

To be fair, his computer cannot generate all 36^32 values, as he has a very
small subset of the MAC address space. Holding down F5 would run him through
his remaining number of timestamps, but certainly not the entire GUID space.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
R

Rob Meade

...
Then I suggest using their e-mail address as the username (which is actually
quite common). *Anything* you generate for them is going to be another
hard-to-remember string that they're going to write on a sticky, forget,
etc.

Hi again Aaron,

I'd not actually thought of using their email address, figured it would look
more 'professional' to fire out a licence key with the app (not that it
means much I guess!)...anyway, I'll do that - cheers for the suggestion and
GUID help :)

Rob
 
R

Rob Meade

...
The number of combinations is 36 ^ 32. Think about this for a second... 36
^ 6 exceeds the upper boundary for an INT datatype (~2 billion). 36 ^ 13
exceeds the upper boundary for a BIGINT datatype
(9,223,372,036,854,775,807). So take that latter number, square it, and
then multiply that by 2 billion.

Again, being that my maths is pants, I'm assuming the ^ is "to the power
of" - not really sure what that means either, but I just love the fact that
the number is over 9 million, million, million * 2 billion! ROTFL! Wonder
why they stopped there???? You think someone thought - "nah, they'll never
need anything bigger than that, I'm sure...." - hehe....one day though...one
day :eek:D
This is no RAND(), trust me.

hehe

Cheers - I've had quite a chuckle here :eek:)

Rob
 
R

Rob Meade

...
To be fair, his computer cannot generate all 36^32 values, as he has a very
small subset of the MAC address space. Holding down F5 would run him through
his remaining number of timestamps, but certainly not the entire GUID
space.

*WHOOOOOOOOOOOOOSH*

LOL...not sure if thats a compliment, a dig, or just a passing comment -
erm...thanks anyway :eek:D

Rob
 
M

Mark Schupp

here is an explanation of GUIDs (DCE UUIDs) and how they are constructed

http://www.opengroup.org/onlinepubs/9629399/apdxa.htm

Microsoft apparently uses a slightly different format (the described format
includes a flag to indicate this) but I have never been able to find a
description of the algorithm that they use. If anyone knows, I would
appreciate a link to it.

If reference to the original poster's needs. I would suggest that a license
key be shipped with the product but that when they register so that they can
get updates a more user-friendly id and password be generated. Associated
the license key with that user id in a database so that you can trace users
back to their license keys.

I would also use a license key format that included some information about
the product and the licensed user rather than a GUID. That way the
application can test the validity of the license during operation.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,225
Members
46,815
Latest member
treekmostly22

Latest Threads

Top