File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generating a Product Activation Code

 
Stuart Rogers
Ranch Hand
Posts: 141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings all,

This method creates a 16-character PAC consisting of only digits 0-9 and upper- and lowercase letters


This works, but I'm wondering if someone has a better way. Specifically, this has the possibility of
throwing chains of identical characters ie:
4j64xYYvk2 - 2 Y's
6i4xYYY7k4 - 3 Y's
u3bNNNN5q - 4 N's

how could the method be massaged to ensure there are no chains?

As usual, all comments, suggestions, positive criticism and especially examples are all welcome.

TIA,

Still-learning Steve
 
Paul Clapham
Sheriff
Pie
Posts: 20196
26
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Off the top of my head I can think of two ways to deal with that:

(1) Don't worry about it (why is it a problem anyway?)

(2) If you get a code which flunks the no-consecutive-repeats rule, throw it out and get another one. Repeat until satisfied.

(3) ... okay I'm thinking as I type, it looks like... If you get a code which flunks, find the guilty characters and replace them by some other character which allows the code to pass.
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuart Rogers wrote:how could the method be massaged to ensure there are no chains?

That is easy - if the character you've just generated is the same as the previous one, throw it away and get a new one. Eventually a different character must come up, otherwise your random generator would not deserve to be called random.

The hard part is - how is your application going to verify the given activation code is valid?
 
Martin Vajsar
Sheriff
Pie
Posts: 3747
62
Chrome Netbeans IDE Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another suggestions: stick to the numbers and upper-case letters and remove any numbers/letters that could be mistaken for another one (0 and O, 1 and I and so on). It helps the user tremendously if he needs to verify that the code has been entered correctly. A set of 32 characters I once used for this kind of functionality was 23456789ABCDEFGHJKLMNPQRSTUVWXYZ. If you plan to supply the code solely in a digital form, it is not as important.
 
Stuart Rogers
Ranch Hand
Posts: 141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After some rejiggering...


works great. Yes I can see where removing the look-alike characters and digits would improve the user experience, "5" can look like an "S" too.

Thanks to all who replied!

CASE CLOSED

Still-learning Steve
 
Stuart Rogers
Ranch Hand
Posts: 141
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright, one more pass at this, merging advice from those with more experience...


Thanks to all who replied! Hope this helps someone else

Still-learning Steve
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic