• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

generating a Product Activation Code

 
Ranch Hand
Posts: 141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Vashko
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic