*:*************************************
*:* Coded by Brian Altman
*:*************************************
*:* Inspired by 'simple VFP DLL; code by
*:* Calvin Hsia and John Koziol
*:* found at http://blogs.msdn.com/vsdata/
*:*************************************
*:* Save this portion as a prg and run 1st
*:* Change the 'secret string' or add a more
*:* complicated function to customize
*:*************************************
Code:
IF FILE("baprot.dll")
DECLARE integer DllUnregisterServer IN baprot.dll
?DllUnregisterServer()
CLEAR DLLS
ENDIF
SET TEXTMERGE TO baprot.prg
SET TEXTMERGE ON NOSHOW
\DEFINE CLASS baprot AS Session OLEPUBLIC
\PROCEDURE PassProtect
\if FILE("pass.txt")
\ lnPassword=FILETOSTR("pass.txt")
\else
\ RETURN .f.
\endif
\if SYS(2007,SYS(0)+"YourSecretString")==ALLTRIM(TRANSFORM(lnPassword))
\ RETURN .t.
\else
\ RETURN .f.
\endif
\ENDPROC
\ENDDEFINE
SET TEXTMERGE TO
BUILD PROJECT baprot FROM baprot
BUILD DLL baprot FROM baprot
*:*************************************
*:* Now your dll is built, call it with this
*:* code from a second prg.
*:*
*:* Figure out what your password should be
*:* using ?SYS(2007,SYS(0)+"YourSecretString")
*:*
*:* For 'true' protection, place some critical
*:* apps functions/methods in the same dll
*:* that can only be fired once the password
*:* is validated.
*:*************************************
Code:
loPass=NEWOBJECT("baprot.baprot")
if FILE("pass.txt")=.f. or lopass.PassProtect=.f.
lnPass=INPUTBOX("Enter Password")
STRTOFILE(lnpass,"pass.txt")
ENDIF
IF lopass.PassProtect
MESSAGEBOX("success!")
ELSE
MESSAGEBOX("failure!")
ENDIF