Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Generate random string

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


  #2  
Old July 19th, 2005, 01:44 PM
Aaron [SQL Server MVP]
Guest
 
Posts: n/a
Default Re: Generate random string

Why not just use a GUID?

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Rob Meade" <robb.meade@NO-SPAM.kingswoodweb.net> wrote in message
news:9nIxc.2252$PQ.20197614@news-text.cableinet.net...[color=blue]
> 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[/color]
I[color=blue]
> would like them to be auto generated and a check made to see whether or[/color]
not[color=blue]
> 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[/color]
very[color=blue]
> 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[/color]
occured[color=blue]
> to me that I'm probably just reinventing the wheel a bit here, someone[/color]
must[color=blue]
> have done this before!
>
> Has anyone produced anything similar to this in the past?
>
> Any help would be appreciated.
>
> Regards
>
> Rob
>
>[/color]


  #3  
Old July 19th, 2005, 01:44 PM
Dave Anderson
Guest
 
Posts: n/a
Default Re: Generate random string

Rob Meade wrote:[color=blue]
>
> 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?[/color]

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.


  #4  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Thanks - but how will it..

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


  #5  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

Ok - so I got this:


  #6  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

(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


  #7  
Old July 19th, 2005, 01:44 PM
Aaron [SQL Server MVP]
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

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

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Rob Meade" <robb.meade@NO-SPAM.kingswoodweb.net> wrote in message
news:u7Jxc.6$bD1.288991@news-text.cableinet.net...[color=blue]
> 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[/color]
two -[color=blue]
> but if you happen to reply prior to that - how many characters does this
> generate by the way?
>
> Thanks again,
>
> Rob
>
>[/color]


  #8  
Old July 19th, 2005, 01:44 PM
Aaron [SQL Server MVP]
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

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!

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Rob Meade" <robb.meade@NO-SPAM.kingswoodweb.net> wrote in message
news:S9Jxc.8$NF1.343296@news-text.cableinet.net...[color=blue]
> (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[/color]
to[color=blue]
> remember etc...(great for uniqueness mind!)...
>
> Thoughts/suggestions...
>
> Rob
>
>[/color]


  #9  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

"Aaron [SQL Server MVP]" wrote ...
[color=blue]
> Why does a serial # have to be easy to remember?[/color]

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

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

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

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

Regards

Rob


  #10  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

"Aaron [SQL Server MVP]" wrote ...
[color=blue]
> Well, GUID stands for Globally Unique IDentifier, so you can do the math
> from there...[/color]

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)..
[color=blue]
> Keep this in mind, of course, if you are going to generate or[/color]
response.write[color=blue]
> from ASP:
> http://www.aspfaq.com/2358[/color]

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

Rob


  #11  
Old July 19th, 2005, 01:44 PM
Aaron [SQL Server MVP]
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

> They'll have a password as well as the key Aaron, the licence number I
guess[color=blue]
> is affectively their username.[/color]

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


  #12  
Old July 19th, 2005, 01:44 PM
Aaron [SQL Server MVP]
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

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.

--
http://www.aspfaq.com/
(Reverse address to reply.)




"Rob Meade" <robb.meade@NO-SPAM.kingswoodweb.net> wrote in message
news:jNJxc.53$i12.852173@news-text.cableinet.net...[color=blue]
> "Aaron [SQL Server MVP]" wrote ...
>[color=green]
> > Well, GUID stands for Globally Unique IDentifier, so you can do the math
> > from there...[/color]
>
> Whilst not really wanting to go down this road, but feeling propelled to[/color]
say[color=blue]
> 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[/color]
was[color=blue]
> 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)..
>[color=green]
> > Keep this in mind, of course, if you are going to generate or[/color]
> response.write[color=green]
> > from ASP:
> > http://www.aspfaq.com/2358[/color]
>
> Thanks for that, I didnt even know about the GUID ability in ASP so I've
> learnt something new tonight :o)
>
> Rob
>
>[/color]


  #13  
Old July 19th, 2005, 01:44 PM
Evertjan.
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

Aaron [SQL Server MVP] wrote on 09 jun 2004 in
microsoft.public.inetserver.asp.general:
[color=blue]
> 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.
>[/color]

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.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
  #14  
Old July 19th, 2005, 01:44 PM
Aaron [SQL Server MVP]
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

> 1 : to talk in a noisy, excited, or declamatory manner[color=blue]
> 2 : to scold vehemently
> transitive senses : to utter in a bombastic declamatory fashion
>
> ================
>
> But then, Aaron, we trust you.[/color]

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

A


  #15  
Old July 19th, 2005, 01:44 PM
Dave Anderson
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

Aaron [SQL Server MVP] wrote:[color=blue][color=green]
>> ...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???
>>[/color]
> 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.[/color]

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.


  #16  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

"Aaron [SQL Server MVP]" wrote ...
[color=blue]
> Then I suggest using their e-mail address as the username (which is[/color]
actually[color=blue]
> 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.[/color]

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


  #17  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

"Aaron [SQL Server MVP]" wrote ...
[color=blue]
> The number of combinations is 36 ^ 32. Think about this for a second...[/color]
36[color=blue]
> ^ 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.[/color]

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 :oD
[color=blue]
> This is no RAND(), trust me.[/color]

hehe

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

Rob


  #18  
Old July 19th, 2005, 01:44 PM
Rob Meade
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

"Dave Anderson" wrote ...
[color=blue]
> To be fair, his computer cannot generate all 36^32 values, as he has a[/color]
very[color=blue]
> small subset of the MAC address space. Holding down F5 would run him[/color]
through[color=blue]
> his remaining number of timestamps, but certainly not the entire GUID[/color]
space.

*WHOOOOOOOOOOOOOSH*

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

Rob


  #19  
Old July 19th, 2005, 01:45 PM
Mark Schupp
Guest
 
Posts: n/a
Default Re: Thanks - but how will it..

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.

--
Mark Schupp
Head of Development
Integrity eLearning
www.ielearning.com


"Rob Meade" <robb.meade@NO-SPAM.kingswoodweb.net> wrote in message
news:jNJxc.53$i12.852173@news-text.cableinet.net...[color=blue]
> "Aaron [SQL Server MVP]" wrote ...
>[color=green]
> > Well, GUID stands for Globally Unique IDentifier, so you can do the math
> > from there...[/color]
>
> Whilst not really wanting to go down this road, but feeling propelled to[/color]
say[color=blue]
> 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[/color]
was[color=blue]
> 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)..
>[color=green]
> > Keep this in mind, of course, if you are going to generate or[/color]
> response.write[color=green]
> > from ASP:
> > http://www.aspfaq.com/2358[/color]
>
> Thanks for that, I didnt even know about the GUID ability in ASP so I've
> learnt something new tonight :o)
>
> Rob
>
>[/color]


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles