Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Protection Plus for Clipper - <u>pp_ucode()</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
PP_UCODE()
Return user (hidden) code
------------------------------------------------------------------------------

Syntax
  PP_UCODE( <nNumber> )  .  nResult

Arguments
  <nNumber> is the number input from the user.

Returns
  Number between 0 and 18.

Description
  Compares the code entry value passed to today's code entry
  numbers for the given code entry random number generated
  previously with pp_cenum().  If the value is correct, it returns
  a number from 1-18 to represent the "hidden" function to be
  run.  Otherwise, a zero is returned indication either an error in
  parameter type or invalid code.  This is where the great
  flexibility lies in the PROTECTION PLUS library.  You have
  the complete control over what you want to do, and what you
  would like to hide from your users, while still keeping the
  capability of your procedures available at your request.

Example

*The following example is from an application's power-up screen.  *The
first thing here is the entering of the password.  Notice how *a set
key statement is used for the user-code function.

set key -4 to ucode           && F5 for hidden routines
password=space(8)
do while empty(password) .AND. !lastkey()=27
    @ 20,28 clear to 20,60
    @ 20,30 say "Password: " get password picture "@!"
    read
enddo
set key -4 to

* Write your own code here to test password and continue program
* if ok.

if password#"PROPLUS "
    pp_upddate()
    set color to
    clear
    @ 2,0 say "Incorrect password entered, program aborted!"
    @ 4,0 say ""
    cancel
endif

* At this point, the program is allowed to continue.  This is where
* you would stick the first "DO" command to execute your main
* menu or whatever you do next.

do main_menu

--------------------
This function UCODE() you create to get the secret number after the
user signals the code entry key sequence, whatever you define.  For
the purposes of this demo, only the result routine number is printed
on the screen.  In your application, you could set up a set of case
statements for each value (1-18) to carry out your routines.  A zero
is returned if an invalid value was entered.  The program can execute
a function and continue with the program or execute a function and
cancel to dos.  You have complete control!  All of these functions
drop to dos after executing.

FUNCTION ucode
    PRIVATE _routine
    clear gets
    get_code=0
    @ 20,28 say "Enter code: " get get_code picture "@Z"
    read
    if lastkey()=27
        retu .T.
    endif
    _routine=pp_ucode(get_code)
    set color to
    clear
    do case
        case _routine=1                  && unlock application
            if pp_unlock()
                @ 2,0 say "Application unlocked..."
            endif
        case _routine=2                  && advance payment date
            if pp_nexptype("P",pp_npdate(date(),20))
                @ 2,0 say "Application payment expire date "+;
                    extended to "+dtoc(pp_npdate(date(),20))
            endif
        case _routine=3                  && kill protection from disk
            if pp_killprot()
                @ 2,0 say "Protection erased!"
            endif
        case _routine=4
            if pp_nexptype("D",ctod("4/10/91"))
                @ 2,0 say "Application demo expire date set "+;
                  "to 4/1/91"
            endif
        case _routine=10                 && write copy protection file
            pp_copywrite()
        case _routine=0                  && error
            retu .F.
    endcase
    @ 4,0 say ""
    exit_program()
return .T.

See Also: PP_NEXECT() PP_NEXELM() PP_NEXPTYPE() PP_NPDATE() PP_UNLOCK()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson