Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to give registration keys for warranty 1

Status
Not open for further replies.

rresendez

Programmer
Mar 14, 2005
40
US
I need to create a unique registration key for each of my program CD's for warranty purposes. They will only be used for the user to register his/her copy for warranty, support, and upgrades. I do not need it to try to limit where the software is installed. Like that will ever be possible. Anyway, I don't want to give it in any particular order, so that someone can quess a serial (or registration) number, if that is possible. Also, where is the best place to place it in the program?

Can anyone help?

Thanks,
Ramon
 
Ramon,

Would SYS(2015) work for you?

Or, check the coCreateGuid API call. A Guid is guaranteed to be globally unique, although with 16 seemingly random letters and digits to enter, you won't win any thanks from your customers.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Thanks Mike,

I don't really need them to enter the registration number to install or run the program and I don't want to inconvience them. I only need it for when they register it with me for support and upgrades. I guess I could make up my own numbers. It would be nice to give them the choice to register online or by the registration card.

Ramon
 
Ramon,

In that case, I'd suggest you write a little function to generate a simple 4-character code. They don't need to be totally unique, and when eventually you run out of combinations, you could just start again.

Good luck with the application.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike,

I actually used your suggestion on the SYS(2015) and it is what I think worked best. I wanted to replace the underscore with RR and put a "S" for Single or "N" for Network at the end. So, I did the following small program for the "S":

CLEAR

x=1

DO WHILE x<1000

*USE serialnum
*SET UNIQUE ON

APPEND BLANK
x=RECNO()

serial_no=SYS(2015)
serial_no=ALLTRIM(serial_no)
snum=SUBSTR(serial_no,2,10)
ser_num="RR"+snum
ser_num=ser_num+"S"

GOTO x
REPLACE serialnum WITH ser_num

REINDEX

ENDDO

Maybe this will help someone else. I did another small program, but having it add the "N" at the end. I now have 1000 for the Single verion and 1000 for the Network version.

Thanks so much Mike. A star for you again.
Ramon

 
Here's an idea...

Code:
clear

* Generate Serial Numbers
=GenerateSerialNums()

* Simulate obtaining a series of Network and Single serial numbers
local cNextSN, i
for i = 1 to 20
  cNextSn = NextSN(iif(mod(i,2)==0,"N","S"))
  ? cNextSn
next

****
function NextSN
  lparam cSnType
  local array aNextSn[1]

  select top 1 cSn ;
    from SNS ;
    where right(cSn,1)==cSnType .and. !Issued ;
    order by cSn ;
    into array aNextSn

  update SNS set Issued = .t. where cSn = aNextSn[1]

  return aNextSn[1]

endfunc

****
procedure GenerateSerialNums
  create cursor SNS (SnId c(6),cSn c(15),Issued l)
  index on cSn tag cSn candidate

   local i, j, bError

   on error bError = .t.

  for j = 1 to 2 && Generate Network and Single serial numbers

    for i = 1 to 1000

      insert into SNS ;
        (SnId,cSn) values ;
        (iif(j==1,"N","S")+padl(trans(i),5,"0"),GenUniqueSerialNum()+iif(j==1,"N","S"))

      if bError && Incase running on a very fast machine and you get the same value
        i = i - 1
        bError = .f.
      endif

    next

  next

  on error
endproc

function GenUniqueSerialNum
  local cSnIn, cSnOut, i, nLen, j
  cSnIn = substr(sys(2015),2)
  nLen = len(cSnIn)
  cSnOut = ""
  for i = 1 to nLen step 2
    cSnOut = cSnOut + substr(cSnIn,i,2) + "-"
  next
  return left(cSnOut,len(cSnOut)-1)+left(trans(rand()*100),1)
endfunc
 
Ramon,

You mention you mainly want to give them a code that they can't easily guess. You may consider, then, a checksum of some sort.. perhaps one that is easily computed without a computer.

Credit cards use a "MOD 10" checksum, basically adding together all the digits and placing as an additional digit just the "ones place" digit from the sum. This would be easy with a small number of digits:
12345
1+2+3+4+5=15 ... 15 MOD 10 = 5, so the final reg key is: 123455

2+3+4+5+6=20 ... 20 MOD 10 = 0, so: 234560

If you have several varieties of your product, or several different products, you could start with a different number for each product.

If you want to be even more obscure (and make it nearly impossible to verify a reg key without typing it into your own evaluator program) you can use letters, too, and use the ASC() value of the letter as input to your checksum/hash algorithm. One other benefit to using letters too is the leading letter can then be an abbreviation of the program's name (say, "S" for "Super Accounting Program", etc). You can also get more complicated, perhaps XORing instead of simply Adding... or combining an unknown "password" with the visible key, so that a user can't just guess at XOR/Adding algorithms.

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top