Number licence xxxx-xxxx-xxxx-xxxx

Postby Jeff Barnes » Tue Oct 21, 2008 2:37 pm

Hi David,

I hope this is the correct code :-)

It's been a while since I've made any changes to it.


Code: Select all  Expand view
#include "Fivewin.ch"

/* KeyGen
   Developed by Jeff Barnes  (jeff@can-soft.net)
   Last Revised: March 18 2004


   MakeKey(nKey, nLicense)     //Returns cKey
   nKey = any numeric value
   nLicense = Number of licenses to be allowed
   

   MakeKey()      //Returns cKey
   This will ask for nKey, nSerial and nLicense

   VerifyKey(nKey, nLicense, cKey)   //Retruns logical .t. or .f.
   nKey = numeric value -must be same number as used in MakeKey()
   nLicense = numeric value -must be same number as used in MakeKey()
   cKey = The Key to be verified -generated from MakeKey()

   GetLicense(nKey, cStored)   //Returns nLicense
   nKey = numeric value -must be same number as used in MakeKey()
   cStored = the key returned by MakeKey()

   GetSecretKey( nSerial, cKey ) //Returns Secret Key
   nSerial = serial number of hard drive ( nSerialHD )
   cKey = The ket returned by MakeKey()

*/

Static cStored, cKey, nSerial, oKeyGen

Function MakeKey(nKey,nLicense,lGetSecretKey, nSerial2)
   Local nTotal1:=0, nTotal2:=1,nTotal3:=0
   Local cDigit, i, lVisable:=.f.
   Local cHash1:=0, cHash2:=0, cHash3:=0, cHash4:=0
   Local cKey:=""
   Local nCount:=0
   Local nSerial:=nSerialHD(), oClp

   IF Empty(lGetSecretKey)
      lGetSecretKey := .f.
   ELSE
      nSerial := nSerial2
   ENDIF

   if Empty(nLicense)
      nLicense:=1
   endif

   if Empty(nKey)
      lVisable:=.t.
      nKey:=1
      nSerial:=0
      MsgGet("Key Generator","Enter Key: ",@nKey)
      MsgGet("Key Generator","Enter Serial Number: ",@nSerial)
      MsgGet("Key Generator","Number of Licenses: ",@nLicense)
   endif
   nCount:=len(alltrim(str(nSerial)))
   For i = 1 to nCount+1
       cDigit := SubStr( alltrim(str(nSerial)) ,i,1)
       nTotal1:=nTotal1+val(cDigit)
       if val(cDigit)<>0
          nTotal2:=nTotal2*val(cDigit)
       endif
       nTotal3:=nTotal3+(val(cDigit)*nCount)
   Next
   cHash1:=alltrim(str(nTotal1*nCount+nKey))
   cHash2:=alltrim(str(nTotal2*nCount+nKey))
   cHash3:=alltrim(str(nTotal3*nCount-nKey))
   cHash4:=alltrim(str(nLicense*nCount*nKey))

   cKey:= cHash1+"-"+cHash2+"-"+cHash3+"-"+cHash4
   
   IF lVisable
      MsgInfo("Serial Number: "+str(nSerial)+CRLF+"Key: "+cKey,"Key Generator")
      Define Window oKeyGen FROM 0,0 to 0,0
      Define CLIPBOARD oClp of oKeyGen
      Activate CLIPBOARD oClp
      oClp:SetText("Serial Number: "+str(nSerial)+CRLF+"Key: "+cKey+CRLF+"Licenses: "+str(nLicense))
      MsgInfo("The KEY has been copied to the clipboard")
      Activate Window oKeyGen on init oKeyGen:End()
   Endif
Return cKey



Function VerifyKey(nKey,cStored)
   If Empty(nKey) .or. Empty(cStored)
      MsgInfo("A value is missing for VerifyKey()","KeyGen Error")
      Return .f.
   endif
   If MakeKey(nKey,GetLicense(nKey,cStored)) = cStored
      Return .t.
   else
      Return .f.
   endif
return nil
   
Function GetLicense(nKey,cStored)
   Local nLicense, i, j:=0, cHash4:="", nCount
   If Empty(nKey) .or. Empty(cStored)
      MsgInfo("A value is missing for GetLicense()","KeyGen Error")
      Return Nil
   endif

   nCount:=Len(alltrim(cStored))
   for i = 1 to nCount
       if substr(cStored,i,1)="-"
          j=j+1
       endif
       if j=3
           if substr(cStored,i,1)<>"-"           
             cHash4:=cHash4+substr(cStored,i,1)
           endif
       endif
   next
   nLicense:=val(cHash4)/nkey/ ( len( alltrim( STR( nSerialHD() ))))
return nLicense


Function GetSecretKey( nSerial, cKey )
   Local cSecret
   if empty(nSerial)
      MsgInfo("You MUST supply a Hard Drive Serial Number","ERROR")
      Quit
   ENDIF
   if empty(cKey)
      MsgInfo("You MUST supply a Key [ made by MakeKey() ]","ERROR")
      Quit
   ENDIF

   DEFINE WINDOW oKeyGen FROM 0,0 to 5,35 TITLE "Key Generator"
   ACTIVATE WINDOW oKeyGen on INIT cSecret:=DoSecret( nSerial, cKey )
Return cSecret

Function DoSecret( nSerial, cKey )
   Local nSecret := 0, lSearching := .t., nCount, i:=0, j
   Local cGetKey, cTempKey:="", cTemp:=""
   Local cHash1:="", cHash2:="", cHash3:="", cHash4:=""
   Local cGetHash1:="", cGetHash2:="", cGetHash3:="", cGetHash4:=""
   Local oSay

   IF ! MsgYesNo("This may take a LONG TIME to run, Continue?","Find Secret Key")
      Quit
   ENDIF

   FOR j = 1 to len(trim(cKey))
      i++
      cTemp := SUBSTR( cKey, i, 1 )
      cTempKey = cTempKey + cTemp
      IF cTemp = "-"
         if EMPTY( cHash1 )
            cHash1:=Left( cTempKey,len( trim( cTempKey ))-1 )
            cTempKey:=""
            loop
         endif
         if EMPTY( cHash2 )
            cHash2:=Left( cTempKey,len( trim( cTempKey ))-1 )
            cTempKey:=""
            loop
         endif
         if EMPTY( cHash3 )
            cHash3:=Left( cTempKey,len( trim( cTempKey ))-1 )
            cTempKey:=""
            loop
         endif
      ENDIF
   NEXT

   lSearching := .t.

   DO WHILE lSearching
      i++
      @ 1,1 SAY "Working..."+STR(i) of oKeyGen COLOR "R+/W"
      SysWait()
      cGetKey := MakeKey( i, 5, .t., nSerial )
      cGetHash1:=left(cGetKey,len(cHash1))
      cGetHash2:=substr(cGetKey,len(alltrim(cHash1))+2,len(alltrim(cHash2)))
      cGetHash3:=substr(cGetKey,len(alltrim(cHash1))+len(alltrim(cHash2))+3,len(alltrim(cHash3)))

      if cHash1=cGetHash1 .and. cHash2=cGetHash2 .and. cHash3=cGetHash3
         @ 1,1 SAY "Done....................." of oKeyGen COLOR "R/w"
         SysWait()
         MsgInfo("You Secret Key is: "+STR(i),"Secret Key Finder")
         oKeyGen:End()
         lSearching := .f.
      endif
   ENDDO
Return i





Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

KeyGen32

Postby David Williams » Tue Oct 21, 2008 4:55 pm

Hi Jeff

Thank you for that, all checked out and working! 8)
Just what I needed.

Regards
David
User avatar
David Williams
 
Posts: 82
Joined: Fri Mar 03, 2006 6:26 pm
Location: Ireland

Postby triumvirato » Wed Oct 22, 2008 5:27 pm

Silvio,

Silvio wrote:Good Mr Rochinha

BUT NOT FOUND RANDOM FUNCTION


look for this in Rochinha's message?

Rochinha wrote:Function GerarSenha(MaxNum,Tipo)
* 1 = Somente Numeros
* 2 = Numero e Letras
* 3 = Somente Letras
local chave := ""
var_valores := { "0123456789",;
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",;
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" }[Tipo]
for i = 1 to MaxNum
num := random(len(var_valores))
chave := chave + substr(var_valores,num,1)
next
return lTrim(chave)
triumvirato
 
Posts: 199
Joined: Tue Apr 22, 2008 9:54 am
Location: Valladolid, Spain.

Postby Silvio » Thu Oct 23, 2008 7:32 am

triumvirato,
read all the post please
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby triumvirato » Thu Oct 23, 2008 8:01 am

Silvio,

Silvio wrote:triumvirato,
read all the post please


I did, of course. Perhaps you musted be more explicit in what you were looking for. I only try to help you. Sorry.
:)
triumvirato
 
Posts: 199
Joined: Tue Apr 22, 2008 9:54 am
Location: Valladolid, Spain.

Postby Silvio » Thu Oct 23, 2008 8:02 am

you must read all posts
you can found random function
Best Regards, Saludos

Falconi Silvio
User avatar
Silvio
 
Posts: 3107
Joined: Fri Oct 07, 2005 6:28 pm
Location: Teramo,Italy

Postby triumvirato » Thu Oct 23, 2008 8:04 am

Ok. That's all.
triumvirato
 
Posts: 199
Joined: Tue Apr 22, 2008 9:54 am
Location: Valladolid, Spain.

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 90 guests