'===========================================================================
' Subject: REGISTRATION KEY VALIDATION        Date: 09-25-93 (00:33)       
'  Author: Peter Mikalajunas                  Code: QB, QBasic, PDS        
'  Origin: QBTIPS_R.DOC                     Packet: ALGOR.ABC
'===========================================================================
' Written by Peter Mikalajunas
' Sept 1993
' I am releasing this routine into the public domain
' I hope you find it useful.  It is just a starting point
' for a simple validation program.
' There are any number of ways to implement this routine
' You can either parse a command line, setup a reg program
' that imbeds the Owner and Serial number in the exe
' or have your program look for a seperate file containing them.
' I would appreciate any suggestions, comments, improvements, etc.
' As a side note, this program will execute in Qbasic

DECLARE SUB Validate (Owner$)

CLS
DIM SHARED Serial AS LONG
DIM SHARED SNumber AS LONG
DIM SHARED Valid AS INTEGER

' users name and maybe a zip to help things along,
' that way you don't have too many problems with
' users having the same name.
' The Owner$ is case sensitive

Owner$ = "The User 60304"
Serial = 1083565

Validate Owner$
' rem the next three lines out once you have a valid serial number and user in place
LOCATE 5, 1
COLOR 12, 0
PRINT "The entered Serial number is"; Serial
LOCATE 6, 1

' You can use this IF THEN routine in a number of places in your program

IF Valid = 1 THEN
   COLOR 10, 0: PRINT "Money In the Bank"
ELSE
   COLOR 15, 0: PRINT "Not registered": COLOR 7, 0
END IF

SUB Validate (Owner$)
' Sub routine to be used as part of a software
' registration program. This is simple and straight forward
' granted it can be cracked, but what scheme can't?

Length% = LEN(Owner$) 'Find the Length of the String
Total% = 0   ' Initialize Total at 0

FOR I% = 1 TO Length%
    Temp$ = MID$(Owner$, I%, 1) ' Pick out the Characters one at a time
    Aski% = ASC(Temp$)          ' get the ascii value of each character
    Total% = Aski% + Total%     'add the values together
NEXT I%

M% = 12340
' This number is the "key" to the Generator
'Change it and the following formula any way you want
'one possible use is to set a different number for each
'program or version and then keep track of them.

SNumber = ((Total% + Length%) ^ 2) + M%
IF SNumber = Serial THEN Valid = 1 ' returns 1 if validiation is ok

' rem these next two lines out once you have a number for a user.
COLOR 12, 0
PRINT "The Serial Number is"; SNumber; "for"
COLOR 11, 0
PRINT Owner$

END SUB
