lundi 15 janvier 2018

Anti-forgery unique serial number generation

I need to generate a random serial number to put on holographic stickers in order to let customers check if the purchased product is authentic or not.

Once you input that and query that code it will be nulled, so next time you do it again you receive a message that the product might be fake because the code is already used.

Considering that I should make this system for a factory that produces no more than 2/3 millions pieces a year, for me is a bit hard understand how to set up everything, at least the 1st time…

I thought about 20 digits code in 4 groups (no letters because must be very easy for the user read and input the code)

12345-67890-98765-43210

This is what I think is the easiest way to do everything:

  • The 1st group identifying something like year: 18 and 3 random numbers
  • The 2nd group include a part of GS1 company code (factory producing for different brands)
  • The 3rd completely random
  • last group including 3 random number and a check digit for group 1 and a check digit for group 2

Y= year D= random generated number E= EAN CC= Check Digit

YYDDD-EEEEE-DDDDD-DDDCC

In this way, I have a prefix that changes every year, I can recognize what brand is the product (so I could use one DB source only) and I still have enough random digits to be quite unique if I consider that I will “pick-up” only a portion of the numbers from 10,000,000,000 and 99,999,999,999 and split it following using above sorting

Some questions for you:

  • Do you think I have enough combinations to not generate same code in one year considering 2 million codes? I would not use a lookup in the DB for the same code if it is not really necessary because could slow down batch generation (executed in batch during production process)
  • Considering that backend is in PHP I am thinking to use mt_rand() function, could be a good approach? There are other ways, maybe for functional and professional than mine ;-)

I would avoid using cryptographic complex things like RSA keys and so on… I don’t need that level of security and complexity, I just need a way to generate a unique serial number, most unique as possible that is not easy to be guessed and nulled if you don’t scratch the sticker (so number creation should not be made A to Z, but randomly)




Aucun commentaire:

Enregistrer un commentaire