Page 1 of 1

Registration Code Maker Tutorial and Tool

Posted: Thu Oct 09, 2008 10:00 am
by Rook Zimbabwe
TThe following is a Registration Code Maker tool I use for my software... OK it is a grossly simplified version of what I use.

I have commented the code and it will serve as a good example of what you can do in PB and iss kind of organized OK.

Code: Select all

; Encode and Decode information for REGISTERING PROGRAMS
; Rook Zimbabwe
; allows you to check and see if a program is registered at startup
; this program will function perfectly well as a REGISTRATION CODE MACHINE for you

Enumeration
    #Window_0
EndEnumeration

Enumeration
    #Text_2
    #Text_1
    #Text_0
    #Button_CLR
    #Button_MANGLE
    #String_OUTPUT
    #String_input
EndEnumeration

Structure VisualDesignerGadgets
    Gadget.l
    EventFunction.l
EndStructure

Global NewList EventProcedures.VisualDesignerGadgets()
;-
Procedure UnMangle(regname$, code$)
    ; yep... this is my ACTUAL code...
    Secret$ = "RT673GZAXPOJBNC79DGR6S4F9GJ65ZDGRTH731GDLKOP79SGR7XT6DF2HJ5GAX62GSAT9DH1GXCBR48ROOKZIMBABWERULESU69"
    ; OK you didn't believe that did you? You are going to have to make up your own $ of 100 characters... don't use the number 0
    ; because it looks so much like O
    Result = Len(regname$) ; get the length of the name sent
    If Result < 15 ; if it is too small pad it out
        For new = result + 1 To 16
            regname$ = regname$ + "+" ; pick your own filler character as well
        Next
        Result = 16 ; set Result to new value
    EndIf
    If result > 16 ; too big we are going to CUT it off
        rname$ = Left(regname$,15)
    EndIf
    For numchar = 1 To 16 ; ok now we go down the row
        char$ = Mid(regname$, numchar,1) ; we get each character
        Ascii = Asc(char$) ; determine its ascii value
        Ascii2 = Ascii - 31 ; subtract 31 to get the value to read the Secret$ Mid() this allows for the ! character but shows 1 for the Mid()
        Ascii3 = Ascii3 + Ascii2 ; move along the Secret$ in a line (adds a bit more complexity than a simple substitution)
        If Ascii3 >  100 ;yes, define a constant for the length but it needs to be the actual length / 100 characters here so we wrap at 100
            Ascii3 % Len(Secret$) ; reset the Ascii3 value to the start of Secret$
        EndIf
        output$ = output$ + Mid(Secret$,Ascii3,1)
        Debug "OUTPUT IS: "+ output$
        SetGadgetText(#String_OUTPUT, output$)
        ; in my programs this same function checks the values stored and compares them and then tells the program weather it is registered or not
        ; uncomment it to use...
        ; If output$ = code$
        ;     Debug "WHAZZUP AMIGO!!!"
        ;     REGISTERFLAG = #TRUE  ; TURN OFF PROTECTION
        ; EndIf
        Ascii2 = 0 ; reset values
        Ascii = 0
    Next
EndProcedure
;-
Procedure Button_CLR_Event(Window, Event, Gadget, Type)
    Debug "#Button_CLR"
    SetGadgetText(#String_INPUT, "")
    SetGadgetText(#String_OUTPUT, "")
    SetActiveGadget(#String_INPUT) ; sets the input field to the active gadget for us!
EndProcedure

Procedure Button_MANGLE_Event(Window, Event, Gadget, Type)
    Debug "#Button_MANGLE"
    regname$ = GetGadgetText(#String_INPUT)
    UnMangle(regname$, "whatever the regcode is!")
EndProcedure
;-
Procedure String_OUTPUT_Event(Window, Event, Gadget, Type)
    ; Debug "#String_OUTPUT"
    ; if you  don't rem these out they console gets cluttered
EndProcedure

Procedure String_INPUT_Event(Window, Event, Gadget, Type)
    ; Debug "#String_INPUT"
EndProcedure
;-
Procedure RegisterGadgetEvent(Gadget, *Function)
    
    If IsGadget(Gadget)
        AddElement(EventProcedures())
        EventProcedures()\Gadget        = Gadget
        EventProcedures()\EventFunction = *Function
    EndIf
    
EndProcedure

Procedure CallEventFunction(Window, Event, Gadget, Type)
    
    ForEach EventProcedures()
        If EventProcedures()\Gadget = Gadget
            CallFunctionFast(EventProcedures()\EventFunction, Window, Event, Gadget, Type)
            LastElement(EventProcedures())
        EndIf
    Next
    
EndProcedure
;-
Procedure Open_Window_0()
    
    If OpenWindow(#Window_0, 5, 5, 400, 200, "MANGLER 1.0",  #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_TitleBar | #PB_Window_ScreenCentered )
        If CreateGadgetList(WindowID(#Window_0))
            StringGadget(#String_INPUT, 10, 20, 380, 20, "", #PB_Text_Center)
            RegisterGadgetEvent(#String_INPUT, @String_INPUT_Event())
            StringGadget(#String_OUTPUT, 10, 60, 380, 20, "", #PB_Text_Center)
            RegisterGadgetEvent(#String_OUTPUT, @String_OUTPUT_Event())
            ButtonGadget(#Button_MANGLE, 10, 95, 180, 35, "ENCODE FROM DATA")
            RegisterGadgetEvent(#Button_MANGLE, @Button_MANGLE_Event())
            ButtonGadget(#Button_CLR, 210, 95, 180, 35, "CLEAR ALL FIELDS")
            RegisterGadgetEvent(#Button_CLR, @Button_CLR_Event())
            TextGadget(#Text_0, 10, 5, 85, 15, "INPUT")
            TextGadget(#Text_1, 10, 45, 175, 15, "ENCODED DATA")
            TextGadget(#Text_2, 10, 140, 380, 50, "Enter TEXT or NUMERIC values in the INPUT box..."+Chr(10)+"Press [ENCODE FROM DATA] and your new REGISTRATION CODE will appear!")
            
            
        EndIf
    EndIf
EndProcedure

Open_Window_0()

SetActiveGadget(#String_INPUT) ; sets the input field to the active gadget for us!

Repeat
    
    Event  = WaitWindowEvent()
    Gadget = EventGadget()
    Type   = EventType()
    Window = EventWindow()
    
    Select Event
    Case #PB_Event_Gadget
        CallEventFunction(Window, Event, Gadget, Type)
        
    EndSelect
    
Until Event = #PB_Event_CloseWindow

End

:D I used this for 2 years with no real problems. I had to keep changing Secret$ for each application, but it works fine!

Type in a few emails and see!