TweetFollow Us on Twitter

Registration Tool
Volume Number:12
Issue Number:12
Column Tag:Shareware Tools

Registration Tools

Tools for Providing Convenient Registration for Shareware

by James George, Los Alamos, NM

Note: Source code files accompanying article are located on MacTech CD-ROM or source code disks.

As we put the finishing touches on our shareware masterpieces, we realized that we had forgotten a vital link - a convenient registration method to encourage users to register and pay for the shareware. We looked around and found none, but MacTech saved the day with a timely article suggesting what was needed (Bill Midesitt - “How to Make $1,000 Per Week Stuffing (Virtual) Envelopes, July 1995). We’ve implemented many of the suggestions for the Metrowerks environment in Pascal or C.

We wanted an easy to include module which a) kept asking the user to register, b) provided an easy way for a user to register, c) allowed the author to create registration numbers, and d) allowed any user to un-register a registered copy to be distributed freely. Thus, Register includes the headers, functions, and resources providing the entire user interface and prints the registration form for mailing or faxing.

Include Register in your Metrowerks project by adding Register.c and Register.rsrc to your project , and inserting two lines in your setup/main module.

Listing 1: Typical Mac Template

Typical Mac Template

Include the Register headers, and check the registration.

#include “Register.h”

main()
{
 (*call usual Macintosh initialization setup routines *)
 
 CheckRegistration();
 
 (* do your event loop *)

}
 

The User Interface

As your application starts, CheckRegistration retrieves the registered name and registration number from the resources, recomputes the registration number from the name and compares it to the registration number from the resource. If these match, CheckRegistration returns and your application continues normally. When they do not match, a information dialog encourages the user to register.

Figure 1. The Information Dialog

Naturally, only the item numbers for the “Register” and “Not Yet” button are important, the rest of the dialog can be modified to promote your application.

If the user chooses “Not Yet”, the application continues normally; but, if “Register” is selected, than the registration dialog allows the information to be entered

Figure 2. The Registration Dialog

The user enters everything but the Registration Number, clicks “Print”, and sends the printed form and fee to YOU! If the user clicks “Cancel” no information is remembered; if the user click “OK”, everything is remembered except the credit card information.

When you receive the registration, you fire up your master copy, enter some special command and the MakeRegistration dialog allows you to enter the information, create a valid registration number from the users name (click on “Make Registration”), and print the information to return to the user.

Figure 3. The Make Registration Dialog

The Details

Now let’s look at the code in detail.

Listing 2: Register.h

Register.h
#define lockedAlert  400  /* application locked alert */
 
#define shareSplashAlert  401 /* the info screen */
 
#define registerDLog 314  /*the register dialog */
#define regPrintItem 3
#define regMkPwdItem 4
#define regFrstPrtItem    5
#define regLastPrtItem    19
#define regFrstOtherSaveItem12
#define regLastOtherSaveItem13
#define regNameItem11
#define regNumberItem19
 
#define regDataResType    ‘ABCD’
 
#define regNumSeedValue   1234/* seed value for test */
 
typedef long *longptr, **longhan;

 /* Prototypes */

void PrintRegForm(DialogPtr theDialog);
long ComputeRegistration(Str255 name);
void MakeRegistration(void);
void UnRegister(void);
void Register(void);
void CheckRegistration(void);

lockedAlert is the id for the alert which informs the user that the application is locked and thus no registration information can be remembered. The “OK” button must remain item 1.

shareSplashAlert is the id for the information alert which describes the features of the shareware and encourages the user to register. The item numbers for “Register” and “Not Yet” item numbers must remain unchanged, but the rest of the dialog may be modified.

registerDLog is the id for the registration (and make registration) dialog. The “OK” and “Cancel” item numbers must remain unchanged, but the rest can be moved as long as the appropriate defines are changed. regPrintItem is the “Print” button and regMkPwdItem is the “Make Registration” button. The items from regFrstPritItem thru regLastPrtItem are printed when the “Print” button is selected. The regNameItem, the regNumberItem and the items from regFrstOtherSaveItem thru regLastOtherSaveItem are saved in the resource file in the resource type regDataResType.

regNumSeedValue is used by the ComputeRegistration routine as the seeded initial value.

longptr and longhan are two data types used, and the prototypes are the actual routines.

Now, lets look at all of the routines which comprise the registration module; they are in Register.c

The registration number is calculated from the name by ComputeRegistration.

Listing 3: ComputeRegistration

ComputeRegistration
long ComputeRegistration(Str255 name)
{
 long   regnum;
 short  i;

 if (StrLength(name) == 0) regnum = -1; 
 else regnum = regNumSeedValue;
 for (i = 1; i<= StrLength(name); i++) 
 regnum = regnum + name[i];
 return (regnum);
}

This computes a registration number for a name, by starting with a seed value, and adding the character code for each character of the name, in order. Although not unique, this allows for many variations by shareware authors. Some of the variations are to change the seed, different arithmetic on individual characters (twice the value, three times the value, alternately add and subtract...). Even these simple techniques can be quite hard to break for the average user, but only a brain teaser for the dedicated hacker.

After an application has started and initializes the Macintosh required managers, it only needs to call CheckRegistration to implement most of the registration functionality; the enhancements will be discussed later.

Listing 4: CheckRegistration

CheckRegistration
// CheckRegistration verifies the remembered name and registration number and asks // the user to register 
the software if the verification fails.

void CheckRegistration(void)
{
 StringHandle  namehan;
 longhanregwdhan;
 long   inregwdnum, computeregwdnum;


 namehan = 
 (StringHandle) GetResource(regDataResType, regNameItem);
 regwdhan = 
 (longhan) GetResource(regDataResType, regNumberItem);
 if ( (namehan != nil) && (regwdhan != nil) )
 {
 if ( 
 (GetHandleSize((Handle) namehan) > 1) &&                      
 (GetHandleSize((Handle) regwdhan) == 4) )
 {
 HLock( (Handle) namehan);
 HLock( (Handle) regwdhan);
 computeregwdnum = ComputeRegistration(*namehan);
 inregwdnum = **regwdhan;
 HUnlock( (Handle) namehan);
 HUnlock( (Handle) regwdhan);
 if ( namehan != nil) ReleaseResource( (Handle) namehan);
 if ( regwdhan != nil) ReleaseResource( (Handle) regwdhan);
 regwdhan = nil;
 namehan = nil;
 if ( inregwdnum != computeregwdnum) Register();
 }
 } else 
 {
 if ( namehan != nil ) ReleaseResource( (Handle) namehan);
 if ( regwdhan != nil ) ReleaseResource( (Handle) regwdhan);
 Register();
 }
}

CheckRegistration gets the remembered name and registration number from the regDataResType resource. If either is not there, then Register is called, otherwise a registration number is calculated from the remembered name and compared to the remembered registration number, and if they differ, then Register is called.

Listing 5: Register

Register
void Register(void)
{
 DialogPtrtheDialog;
 Handle theTextHdl;
 Rect itemBox;
 short  itemHit, theType, index;
 GrafPtrthePort;
 Str255 namestr, regstr;
 long regwordL;
 StringHandle  nameHan, strHan;
 longhanregsHan;


 FlushEvents (everyEvent, 0); /*throws out leftover events */
 if ( Alert(shareSplashAlert, nil) == OK )
 {
   FlushEvents (everyEvent, 0);
 theDialog = 
 GetNewDialog (registerDLog, nil, (WindowPtr) -1);
  if (theDialog != nil)
  {
   /*Hide the Make Reg Number button*/
   HideDialogItem(theDialog,regMkPwdItem);

   /*fill in text fields from save values*/
 strHan = 
 (StringHandle) GetResource(regDataResType, regNameItem);
 if ( strHan != nil) 
 {
 GetDialogItem (theDialog, regNameItem, &theType,              
 &theTextHdl, &itemBox);
   SetDialogItemText (theTextHdl, *strHan);
   ReleaseResource((Handle) strHan);
   }

 for ( index = regFrstOtherSaveItem; 
 index <= regLastOtherSaveItem; index ++)
 {
 strHan = (StringHandle) GetResource(regDataResType, index);
 if (strHan != nil)
 {
 GetDialogItem (theDialog, index, &theType, 
 &theTextHdl, &itemBox);
   SetDialogItemText (theTextHdl, *strHan);
   ReleaseResource((Handle) strHan);
  }
  }
   

  GetPort(&thePort);
 SetPort (theDialog);
  ShowWindow (theDialog); 
  do
  {
   ModalDialog (nil, &itemHit); 
   if ( itemHit == regPrintItem ) PrintRegForm(theDialog);     
  }while (itemHit > cancel);
   
  if ( (itemHit == ok) || (itemHit == regPrintItem) )
   {
   GetDialogItem (theDialog, regNameItem, &theType,            
 &theTextHdl, &itemBox);
   GetDialogItemText (theTextHdl, namestr);
   GetDialogItem (theDialog, regNumberItem, &theType,          
 &theTextHdl, &itemBox);
   GetDialogItemText (theTextHdl,regstr);
   StringToNum(regstr, &regwordL);
   if ( Length(namestr) > 0)
   {
 UnRegister();
 regsHan = (longhan) NewHandle(4);
   nameHan = NewString(namestr);
   **regsHan = regwordL;
   AddResource( (Handle) nameHan, regDataResType,              
 regNameItem , “\p”);
 if ( ResError() != noErr) 
 { itemHit = StopAlert(lockedAlert,nil);}
 WriteResource( (Handle) nameHan);
   AddResource( (Handle) regsHan,regDataResType,               
 regNumberItem , “\p”);
 if ( ResError() != noErr) 
 { itemHit = StopAlert(lockedAlert,nil); }
 WriteResource( (Handle) regsHan);
 UpdateResFile(CurResFile());
 for ( index = regFrstOtherSaveItem; 
 index <= regLastOtherSaveItem; index++)
 {
   GetDialogItem (theDialog, index, &theType,                  
 &theTextHdl, &itemBox);
   GetDialogItemText (theTextHdl,namestr);
   nameHan = NewString(namestr);
   AddResource( (Handle) nameHan,regDataResType, 
 index , “\p”);
 if ( ResError() != noErr) 
 { itemHit = StopAlert(lockedAlert,nil); }
 WriteResource( (Handle) nameHan);
 UpdateResFile(CurResFile());
 }
 }
   }    /*of ok || regPrintItem] */
   
  DisposeDialog(theDialog);
  SetPort(thePort);
 SetCursor(&qd.arrow);
   }
 }
}

Register puts up the information dialog (the shareSplashAlert), and if the user selects the “Register” button, it puts up the registration dialog, prints whenever the “Print” button is clicked, and exits when “OK” or “Cancel” is clicked. When “OK” is clicked, various entered data is remembered; the name, registration number, and fields from regFrstOtherSaveItem thru regLastOtherSaveItem. Register does not verify the registration number, but just remembers the data for the next invocation of the application.

To print the registration form, PrintRegForm is called.

Listing 6: PrintRegForm

PrintRegForm

void PrintRegForm(DialogPtr theDialog)
{ 
 short  index, which, xpos, ypos, theType;
 Handle theTextHdl;
 Rect   itemBox;
 GrafPtr  thePort;
 Str255 thestr, pbuf;
 TPPrPort PPort;
 THPrint  prh;
 Boolean  tmpb;
 TPrStatusstatus;
 Point  pos;
 
 if (regFrstPrtItem <= regLastPrtItem) /* ?something to print*/
 {
  GetPort(&thePort);
 prh = (THPrint) NewHandle(sizeof(TPrint));
 PrOpen();
 PrintDefault(prh);
 tmpb = PrValidate(prh);
 tmpb = PrStlDialog(prh);
 if (PrJobDialog(prh))
 {
 PPort = PrOpenDoc(prh,nil,nil);
 TextFont(times);
 TextSize(12);
 if (PrError() == noErr) PrOpenPage(PPort,nil);
  
  for ( index = regFrstPrtItem; 
 index <= regLastPrtItem; index++)
  {
  GetDialogItem (theDialog, index, &theType, 
 &theTextHdl, &itemBox);
  GetDialogItemText (theTextHdl, thestr);
  if ( StrLength(thestr) > 0)
  {
   xpos = itemBox.left;
   ypos = itemBox.top + 12;
   MoveTo(xpos,ypos);
   for ( which = 1; which <= StrLength(thestr); which++)
   {
   if ( thestr[which] < ‘ ‘)
   {
   ypos= ypos +12;
   MoveTo(xpos,ypos);
   } else DrawChar(thestr[which]);
   if ( thestr[which] == ‘ ‘)
   {
   GetPen(&pos);
   if ( pos.h >= itemBox.right)
   {  
   ypos= ypos +12;
   MoveTo(xpos,ypos);
   }
   }
   }
  }
  }
  if (PrError() == noErr)
  {
   PrClosePage(PPort);
 PrCloseDoc(PPort);
 if ( (**prh).prJob.bJDocLoop == bSpoolLoop)
 PrPicFile(prh,nil,nil,nil, &status);
 }
 PrClose();
 DisposeHandle((Handle) prh);
 SetPort(thePort);
 }
 } 
}

A routine to compute the registration number from the name is provided and uses the same dialog as the registration dialog, with an additional button “Make Registration.” Actually, the button is always present, but hidden by the Registration module. The user sends a printout from the Registration or sends the data electronically, you reenter the data, click “Make Registration,” click “Print” and return a copy with the registration number.

MakeRegistration is called via a pull down menu in the test program but in our actual products, it is called via special hidden commands, since we wanted only one product to maintain and required the ability to make a registration number from any copy of the product. Some possibilities are to install the make menu items as the result of selecting a standard pull down menu with various modifier keys depressed. A very complex mechanism can be constructed, which is easy to execute by the author but difficult to discover.

Listing 7: MakeRegistration

MakeRegistration

void MakeRegistration(void)
{
 DialogPtrtheDialog;
 Handle theTextHdl;
 Rect   itemBox;
 short  itemHit, theType;
 GrafPtrthePort;
 Str255 tmpstr;
 long   regwordL;


 FlushEvents (everyEvent, 0); /*throws out clicks, keys*/
 theDialog = GetNewDialog (registerDLog, nil, (WindowPtr) -1);
 if (theDialog != nil)
 { /*Shows the Make Password button*/
 ShowDialogItem(theDialog,regMkPwdItem);                       
 GetPort(&thePort);
 SetPort (theDialog);
 ShowWindow (theDialog);
 do
 {
 ModalDialog (nil, &itemHit); 
 if (itemHit == regMkPwdItem) /* make register # */
 {
 GetDialogItem (theDialog, regNameItem, &theType, 
 &theTextHdl, &itemBox);
 GetDialogItemText (theTextHdl,tmpstr);
 regwordL = ComputeRegistration(tmpstr);
 NumToString(regwordL,tmpstr);
 GetDialogItem (theDialog, regNumberItem, &theType,            
 &theTextHdl, &itemBox);
 SetDialogItemText (theTextHdl,tmpstr);
  } else 
 if (itemHit == regPrintItem)PrintRegForm(theDialog);
 }while (itemHit > cancel);
   
 DisposeDialog(theDialog);
 SetPort(thePort);
 SetCursor(&qd.arrow);
 }
}


It is advantageous for every shareware user to become an advocate of the product and distribute it widely, but only the unregistered version should be distributed. Thus, an unregistering module is provided and the user is encouraged to distribute the unregistered version to friends, bulletin boards, etc.

Every Macintosh application has an About... module, and we’ve added an unregister button to the About alert, as well as a place for the registered owners name.

Figure 4. The About... Alert

The changes in the About.. module are to retrieve the name from the resource file and display it. If “Unregister” is clicked on, then the unregister module is executed.

Listing 8: AboutApplication

AboutApplication

void AboutApplication(void)
{
 short tmpInt;
 StringHandle  regnameHan;

 regnameHan = (StringHandle)  GetResource(regDataResType,regNameItem);
 if ( regnameHan != nil)
 {
 HLock( (Handle) regnameHan);
 ParamText( *regnameHan, “\p”, “\p”, “\p”);
 HUnlock( (Handle) regnameHan);
 ReleaseResource( (Handle) regnameHan);
 } else ParamText( “\p”, “\p”, “\p”, “\p”);

 tmpInt = Alert(applicationAboutId, nil);
 if ( tmpInt == aboutUnregisterItem) UnRegister();
}

The UnRegister module deletes all of the user data; name, address... from the resources. This results in a version which reverts and asks for the shareware to be registered.

Listing 9: UnRegister

UnRegister
void UnRegister(void)
{
 Handle tmpHan;
 short  index;
 do
 {
 tmpHan = GetResource(regDataResType, regNameItem);
 if (tmpHan != nil)
 { 
 RemoveResource(tmpHan);
 DisposeHandle(tmpHan);
 UpdateResFile(CurResFile());
 }
 } while (tmpHan != nil);
 
 do
 {
 tmpHan = GetResource(regDataResType, regNumberItem);
 if (tmpHan != nil)
 { 
 RemoveResource(tmpHan);
 DisposeHandle(tmpHan);
 UpdateResFile(CurResFile());
 }
 } while (tmpHan != nil);

 for (index = regFrstOtherSaveItem; 
 index <= regLastOtherSaveItem; index++)
 do
 { 
 tmpHan = GetResource(regDataResType, index);
 if (tmpHan != nil)
 { 
 RemoveResource(tmpHan);
 DisposeHandle(tmpHan);
 UpdateResFile(CurResFile());
 }
 } while (tmpHan != nil);
}

Summary

Registration Tools provide a convenient package for generating a registration number based upon a name, gently encouraging the registration of the shareware, providing printed forms for ease of registration, and supporting the broad distribution of unregistered copies. These tools were written with the philosophy that shareware users will register for modest fees if the software performs desired functions, and they are tactfully reminded; we believe that the best way of evaluating shareware is to provide fully functioning software, with documentation.

Registration Tools does not provide copy protection, in fact the user is encouraged to UnRegister and distribute copies! In our examples, the registration is checked only at the beginning and the tests were built with symbol tables enabled; thus, it can be hacked quite easily with a debugger/disassembler. There are many improvements and variations to make “hacking” more difficult but most of us would prefer to get on with creating great shareware for the Macintosh!

We appreciate the excellent review by a MacTech reviewer, and the following is a quote from that review.

So that there is no misunderstanding, it should be made clear that neither the reviewer nor the magazine condone hacking as a way of avoiding payment to authors of commercial or shareware software. The point of this response is to point out to shareware authors the ease with which registration schemes can be bypassed, so that they are under no illusion about the security provided by these schemes. The Registration Tools approach is an effective way to remind users that a shareware fee needs to be paid, while allowing them the opportunity to try out all of the features of the software before deciding whether to purchase it, but it is not a copy protection scheme.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Combo Quest (Games)
Combo Quest 1.0 Device: iOS Universal Category: Games Price: $.99, Version: 1.0 (iTunes) Description: Combo Quest is an epic, time tap role-playing adventure. In this unique masterpiece, you are a knight on a heroic quest to retrieve... | Read more »
Hero Emblems (Games)
Hero Emblems 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: ** 25% OFF for a limited time to celebrate the release ** ** Note for iPhone 6 user: If it doesn't run fullscreen on your device... | Read more »
Puzzle Blitz (Games)
Puzzle Blitz 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Puzzle Blitz is a frantic puzzle solving race against the clock! Solve as many puzzles as you can, before time runs out! You have... | Read more »
Sky Patrol (Games)
Sky Patrol 1.0.1 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0.1 (iTunes) Description: 'Strategic Twist On The Classic Shooter Genre' - Indie Game Mag... | Read more »
The Princess Bride - The Official Game...
The Princess Bride - The Official Game 1.1 Device: iOS Universal Category: Games Price: $3.99, Version: 1.1 (iTunes) Description: An epic game based on the beloved classic movie? Inconceivable! Play the world of The Princess Bride... | Read more »
Frozen Synapse (Games)
Frozen Synapse 1.0 Device: iOS iPhone Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: Frozen Synapse is a multi-award-winning tactical game. (Full cross-play with desktop and tablet versions) 9/10 Edge 9/10 Eurogamer... | Read more »
Space Marshals (Games)
Space Marshals 1.0.1 Device: iOS Universal Category: Games Price: $4.99, Version: 1.0.1 (iTunes) Description: ### IMPORTANT ### Please note that iPhone 4 is not supported. Space Marshals is a Sci-fi Wild West adventure taking place... | Read more »
Battle Slimes (Games)
Battle Slimes 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: BATTLE SLIMES is a fun local multiplayer game. Control speedy & bouncy slime blobs as you compete with friends and family.... | Read more »
Spectrum - 3D Avenue (Games)
Spectrum - 3D Avenue 1.0 Device: iOS Universal Category: Games Price: $2.99, Version: 1.0 (iTunes) Description: "Spectrum is a pretty cool take on twitchy/reaction-based gameplay with enough complexity and style to stand out from the... | Read more »
Drop Wizard (Games)
Drop Wizard 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Bring back the joy of arcade games! Drop Wizard is an action arcade game where you play as Teo, a wizard on a quest to save his... | Read more »

Price Scanner via MacPrices.net

Apple’s M4 Mac minis on sale for record-low p...
B&H Photo has M4 and M4 Pro Mac minis in stock and on sale right now for up to $150 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses. Prices start at only $469: – M4... Read more
Deal Alert! Mac Studio with M4 Max CPU on sal...
B&H Photo has the standard-configuration Mac Studio model with Apple’s M4 Max CPU in stock today and on sale for $300 off MSRP, now $1699 (10-Core CPU and 32GB RAM/512GB SSD). B&H also... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.