aspose file tools*
The moose likes Java in General and the fly likes generating a Product Activation Code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "generating a Product Activation Code" Watch "generating a Product Activation Code" New topic
Author

generating a Product Activation Code

Stuart Rogers
Ranch Hand

Joined: Oct 02, 2008
Posts: 133
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
Bartender

Joined: Oct 14, 2005
Posts: 18115
    
    8

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

Joined: Aug 22, 2010
Posts: 3434
    
  47

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

Joined: Aug 22, 2010
Posts: 3434
    
  47

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

Joined: Oct 02, 2008
Posts: 133
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

Joined: Oct 02, 2008
Posts: 133
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
 
subject: generating a Product Activation Code
 
Similar Threads
Big5 display problem
MD5
socket communication with AS400...
Why is Java's MD5 different from MySQL MD5?
Basic Authentication Servlet Redirect