it protects from running not from copying.
I someone runs the program he needs the license code.
- Code: Select all Expand view
- Function main
IF lizenz() = .T.
Here is your code
else
Msginfo("no lizenz")
ENDIF
Return nil
Best regards,
Otto
Function main
IF lizenz() = .T.
Here is your code
else
Msginfo("no lizenz")
ENDIF
Return nil
#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 (your "secret" password)
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
Silvio wrote:Now
I 'am thinking
to create a connection to my website from fwh application
the procedure must ask to user the name and the user code
and it must to control it into my website
on my site I put a mdb with many record of all users
is it a good Idea?
Jeff Barnes wrote:Hi Silvo,
The method I use is to generate a "reference" number on the users side (basically the hard drive serial number)
The user gives me that number and I run it through my MakeKey() function to generate a "key".
I give this key to the user and they enter it into a field in a config screen.
I put code in my software to Verify this key against the reference number. If VerifyKey() returns "T" it is a valid install and the program runs. Otherwise the program stops.
Here is my code for protecting my software:
- 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 (your "secret" password)
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
I hope this helps.
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 64 guests