Prepare product to accept "Unlock Key".
Sample written in C#
Sample written in Visual Basic .NET

Licensing by secure encrypted license keys provides an easy way to activate application or control from evaluation to full functional version. Manco.Licensing uses a public key encryption to generate and verify encrypted license keys. This schema is more suitable for licensing .NET applications, but you can use it to license .NET controls as well.

Concept

Usually programmers like following behavior for the copy-protected application that uses “Unlock Key” licensing schema:

  1. Application is in the evaluation mode right after downloading. It could be time limited evaluation, or usage limited evaluation or both.
  2. If evaluation is a time limited, then application becomes unusable when evaluation time expires.
  3. When customer buys software it gets Unlock Key.
  4. When Unlock Key is entered the application becomes fully functional.

Let see how it works in .NET Licensing Pro.

The evaluation status of the application is defined by including “Is Evaluation” field to the license type.

The time\running limit is defined by including one of the following “Expiration Dates”, “Expiration Date” or “Expiration Runs” fields to the license type.

The “Unlock Key” field should be included to the license type to force protection library check Unlock Key.

The “Write Key to File” should be included to force protection library write entered “Unlock Key” to the license storage.

If “Is Evaluation” field is included to the License type, the license will be valid (evaluation license is valid license) but have evaluation status. Evaluation status of the license can be checked using license.IsEvaluation property of license object. This status can be used to limit functionality of the application in evaluation mode.

If one of the time\running limit fields has been included to the license type, then application will work till expiration come. Depends on the settings license object can throw exception or set expired status on license. Expiration status of license can be checked using license.IsExpired property.

If unlock key has been entered and it is valid unlock key, then evaluation and expiration statuses will be removed and license become valid. If wrong unlock key has been entered license become invalid.

So, license that uses “Unlock Key” schema can be:

  1. Valid, evaluation, not expired.
  2. Valid, evaluation, expired.
  3. Invalid (wrong unlock key has been entered)
  4. Valid (valid unlock key entered)

Preparation

If you suppose to createnewProduct->Version->List of License Types chain, then the easiest way is to use “New Product Wizard” (see Quick Start). To allow you product use “Unlock Key” licensing schema you should include “License activated by unlock key” predefined type into the license types will be used with your product.

Unlock Key predefined license type

If you suppose to createallProduct->Version->List of License Types chain manually (see "Create New Product manually", Create New Version manually, Create License Type manually sections in help or documentation) or if you have created Product, Version and License Type already, then you can prepare corresponding license type manually. To make license type ready to accept license keys do following steps:

  1. Put marker in the Product tree view on the License Type node which you’d like to prepare.
  2. In the “Available Fields” list check the following attributes: “Is Evaluation”, “Expiration Dates”, “Unlock Key”, “Write Key To File”.
    1. The “Is Evaluation” attribute indicates that license is evaluation till the activation key is entered. This allows you limit some functionality in your product base on the evaluation type.
    2. The “Expiration Dates” attribute indicates that evaluation license will expire in given number of days.
    3. The “Unlock Key” attribute indicates, that license validation will be based on the unlock key. If unlock key is valid, then application become full functional.
    4. The “Write Key To File” attribute is optional, so you can choose whether the activation key should be written to the license file. With “Unlock Key” schema you can use two different approaches to enter unlock key: windows form where your client can enter this key or put the key into the source code using “UnlockKey” property of the License class. The first one can be used only with Windows.Forms applications. The second way it applicable with any type of product. When you use windows forms based method of activation you should write activation key to the file, or else your customer will be asked for a key next time when license is validated. With unlock key located in the source code it’s up to you: do or not write to the file.
  3. Click“-->” button to assign selected attributes to the license type. The license type view will looks like the following: Unlock Key license type
  4. Save changes you’ve made.

Now you should prepare your code to accept license key. If your product is desktop application, then you can allow your users enter unlock key through special window form or using some kind of the configuration file. In any case you should put entered key to the “UnlockKey” property of the license object (see Quick Start). This code should be located before first license validation. It seems that OnLoad event handler of your main form is a good location. Your code could looks like the following:

[C#] 
// Check if the current license is expired or is evaluation license
// Because of the code optimization made by .NET when check
// conditional expressions the IsExpired should be placed
// on the first place.
if (license.IsExpired || license.IsEvaluation)
{
	// This is evaluation license, so 
	// we should show license dialog 
	LicenseForm loForm = new LicenseForm();
	loForm.License = license;
	if (loForm.ShowDialog() == DialogResult.OK
		&& loForm.UnlockKey.Trim() != string.Empty)
	{
		// License information have been entered.
		// Pass it to the license object for the
		// following validation.
		license.UnlockKey = loForm.UnlockKey;
	}
	else if (license.IsExpired)
	{
		// The evaluation license has been expired and 
		// no license information have been entered, 
		// so we should close application.
		Application.Exit();
	}
}

// Now you can use license object to validate license provided with product. 
// It could be unlock key or license file, in any case validation should be done by 
// checking IsValid property of the license object. 
// License will be valid if it is evaluation license,
// or entered valid Unlock Key.
if (license.IsValid)
{
	// Initialize application
	// …
}
else
{
	// License not valid – wrong unlock key has been entered
	// or wrong license file is used 
	MessageBox.Show("License Not Valid",
		"Sample Application",
		MessageBoxButtons.OK,
		MessageBoxIcon.Stop);
	Application.Exit();
}

[Visual Basic .NET] 
' Check if the current license is expired or is evaluation license
' Because of the code optimization made by .NET when check
' conditional expressions the IsExpired should be placed
' on the first place.
If license.IsExpired Or license.IsEvaluation Then
	' This is evaluation license, so 
	' we should show license dialog 
	Dim loForm As LicenseForm = New LicenseForm()
	loForm.License = license
	If loForm.ShowDialog() = DialogResult.OK _
	  And loForm.UnlockKey.Trim() <> String.Empty Then
		' License information have been entered.
		' Pass it to the license object for the
		' following validation.
		license.UnlockKey = loForm.UnlockKey
	ElseIf license.IsExpired Then
		' The evaluation license has been expired and 
		' no license information have been entered, 
		' so we should close application.
		Application.Exit()
	End If
End If

' Now you can use license object to validate license provided with product. 
' It could be unlock key or license file, in any case validation should be done by 
' checking IsValid property of the license object. 
' License will be valid if it is evaluation license,
' or entered valid Unlock Key.
If license.IsValid Then
	' Initialize application
	' …
Else
	' License not valid – wrong unlock key has been entered
	' or wrong license file is used 
	MessageBox.Show("License Not Valid", _
	 "Sample Application", _
	 MessageBoxButtons.OK, _
	 MessageBoxIcon.Stop)
	Application.Exit()
End If
			

Note. Pay attention that we check license expiration status (license.IsExpired) in the code. It means that we wouldn’t like license object through an exception if license is expired during object initialization. To avoid license object throw an exception find implementation of the “BypassExpirationCheck” property in your code and change it to return true value.

[C#] 
/// <summary>
/// Indicates whether the expiration check should be performed
/// inside the license constructor.
/// </summary>
public bool BypassExpirationCheck
{
	get
	{
		// Default return value is false. We change it to true
		// so we could bypass expiration check in the constructor 
		// of the license object so it wouldn't throw exception 
		// and we could use license object to show license information
		// in the license dialog.
		return true;
	}
}
					
[Visual Basic. NET] 
''' <summary>
''' Indicates whether the expiration check should be performed
''' inside the license constructor.
''' </summary>
Public ReadOnly Property BypassExpirationCheck() As Boolean _
Implements Manco.Licensing.ILicenseKeyProvider.BypassExpirationCheck
	Get
		' Default return value is false. We change it to true
		' so we could bypass expiration check in the constructor 
		' of the license object so it wouldn't throw exception 
		' and we could use license object to show license information
		' in the license dialog.
		Return True
	End Get
End Property
					
			

We leave implementation of the LicenseForm on your own, so you can put anything you’d like to it. The simple form can contain some kind of the notification text and text field with length enough to enter 95 characters of the unlock key (80 hexadecimal digits with dash after every fifth digit). You should provide a way to get entered key from the form and put it to the “UnlockKey” property of the license object.

Now you are ready to start issuing the unlock keys. At the first, you should create one purchase licensed for you and leave it with empty “Unlock Key” field. This purchase will be source of the evaluation license file will be provided with your application. It will be single license file you will create for your product, but it should exists and be located in the License folder near you product executable. Field “Unlock Key” in this file should be empty. Put marker to the license type has been prepared for accepting “Unlock Key”. Create new purchase for it:

  1. Main Menu: Action->New Purchase.
  2. Toolbar: “New Purchase” button New Purchase.
  3. Context Menu: right click on the License Type node or License Type View and select New Purchase.

Fill customer’s information with information about your company. Don’t generate unlock key for this purchase. Your purchase information with empty key could looks like following:

Empty Unlock Key

After that you should save information about this purchase (with empty “Unlock Key” attribute) to the license file. To perform this operation you should do one of the following:

  1. Main Menu: Action->Save License To File.
  2. Toolbar: “Save License To File” button Save license.
  3. Context Menu: right click on the Purchase node or Purchase View and select “Save License To File.”

You will see standard file dialog. Select proper location and save license file there. Don’t forget include this license file for your product distribution.

Now you are ready to issue unlock keys for your product. You can generate unlock keys without entering information about purchase, but we recommend you track unlock keys issuing with entering information about purchases. So, to generate unlock key for single customer has paid for your product you need put marker to the corresponding license type node in the product tree view and create new purchase:

  1. Main Menu: Action->New Purchase.
  2. Toolbar: “New Purchase” button New Purchase.
  3. Context Menu: right click on the License Type node or License Type View and select New Purchase.

Fill in information about customer. If you think, that this customer already bought something from you before, then you can fill just part of the information and perform search of the customer:

  1. Main Menu: Action->Customer Search.
  2. Toolbar: “Customer Search” button Search customer.
  3. Context Menu: right click on the Purchase node or Purchase View and select “Customer Search.”

Many, one or no one customers could be found. In case when we have list of customers you will see the following dialog:

Select customer

Select customer by checking corresponding checkbox and click “OK”. Or click “Cancel” if there is not customer meet you needs in the list.

In case when only one customer has been found, the customer information fields will be filled with corresponding information. No dialogs or messages would be shown.

In case when no one customer has been found you will see message box with following text: “No one Customer has been found for a given criteria. This customer will be marked as a new one.”

Generate “Unlock Key” for this purchase:

  1. Main Menu: Action->Generate Unlock Key.
  2. Toolbar: “Generate Unlock Key” button Generate Unlock Key.
  3. Context Menu: right click on the Purchase node or Purchase View and select “Generate Unlock Key.”

Finally view for a new purchase will looks like the following:

Filled Unlock Key

Copy the unlock key from the “Unlock Key” field and paste it to the message you will send to your client.

If you’d like to create unlock keys without entering information about purchases (to send them to separate distributor, for example) you can do the following: put marker to the license type you’ve prepared to accept unlock keys. Then do one of the following:

  1. Main Menu: Action->Generate Unlock Key Bundle.
  2. Context Menu: right click on the License Type node or License Type View and select Generate Unlock Key Bundle.

You will see the following dialog

Generate bundle of the Unlock Keys

Enter number of keys you need and click “Generate” number.

Note: Generation of big number of keys takes a long time.

When generation will be finished you can click “To Clipboard” button to get keys have been generated to the clipboard. After that you can paste keys where you need (to the text of e-Mail, for example). Click “OK” to close dialog.

.NET Licensing Pro Home Page