Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

generating a Product Activation Code  RSS feed

 
Ranch Hand
Posts: 141
  • 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
 
Sheriff
Posts: 23706
50
Eclipse IDE Firefox Browser MySQL Database
  • 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.
 
Sheriff
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • 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
Posts: 3752
62
Chrome Netbeans IDE Oracle
  • 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
  • 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
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!