License Checks

License checks have a crucial role in the protection of your application.

This guide will explain online and offline license checks, their efficient organization within the application, and the implementation of a grace period.

Prerequisites

Before proceeding, make sure you have completed the Getting Started (C++) or Getting Started (.NET/C#) tutorial and accomplished the following steps:

  • Initialize LicenseManager (or LicenseHandler) with your configuration using the appropriate settings.

  • Activate a license for your application.

  • Implement the mechanism to retrieve the current license.

Local Check

Local check does not require an Internet connection and performs the following actions:

1

Verify license state

Verify if the license is enabled, active, and valid. If the license is not in a valid state, it will raise LicenseStateException in C++ or the following exceptions in .Net:

  • LicenseDeletedException

  • LicenseDisabledException

  • TrialLicenseExpiredException

  • LicenseExpiredException

  • LicenseInactiveException

2

Confirm product match

Confirm if the license belongs to the configured product. If the product code of the license and configuration do not match, it will raise ProductMismatchException.

3

Detect clock tampering

Detect cheating with the system clock. If cheating is detected, it will raise ClockTamperedException (C++) or DateTimeCheatingException (.Net).

4

Ensure device binding

Ensure that the license belongs to the device. If the license doesn't belong to the device, it will raise DeviceNotLicensedException.

5

VM detection

If VM detection is enabled, check if the device is a VM and if the license allows virtual machines. If VMs are not allowed and the application is running on a VM, it will raise VMIsNotAllowedException.

6

Floating license timeout

For floating licenses, verify if the floating timeout has expired. If the timeout is expired, it will raise FloatingTimeoutExpiredException.

To perform a local check, call the LocalCheck method:

auto license = licenseManager->getCurrentLicense();
license->localCheck();

Online Check

  • Verify if the license is enabled, active, and valid. If the license is not in a valid state, it will raise LicenseStateException in C++ or the following exceptions in .Net:

    • LicenseDeletedException

    • LicenseDisabledException

    • TrialLicenseExpiredException

    • LicenseExpiredException

    • LicenseInactiveException

  • Synchronize the consumption of consumption licenses and features. If there is not enough consumption left, it will raise NotEnoughConsumptionException.

  • Update the license with data from the license server.

  • Retrieve the most recent installation file for the product.

  • Register a floating license. If there are no floating slots available, it will raise MaxFloatingReachedException.

It can throw the exceptions related to connection issues: NetworkException, NetworkTimeoutException, and LicenseServerException. You can implement a grace period to allow using the application without connection to the server for a limited period.

To run the online check call Check method:

License Check Optimization

License checks can take up to a couple of seconds. It is recommended to run them in a background thread.

Perform local checks on every application startup to ensure the user has a valid license.

However, since calling an online check at every start of the application is redundant, we recommend performing it every few days, using the last check date value saved in the license.

If you need to synchronize consumption more often, you can use SyncConsumption and SyncFeatureConsumption methods.

Grace Period

A grace period can be helpful when you don't want to restrict application usage due to online check failures caused by the lack of an internet connection or internal LicenseSpring server issues.

To implement this, define how long it is allowed to use the application without connecting to the server and handle network exceptions accordingly.

The grace period feature is available in C++ SDK from v7.26.0 and in .Net SDK from v7.22.0. It covers License::check, License::syncConsumption, License::syncFeatureConsumption, and License::sendDeviceVariables methods.

circle-exclamation

By default grace period is 48 hours. You can set another value using:

The License class has methods to check if the grace period started and get the grace period end date:

The grace period starts when one of the covered requests fails and resets after a successful request. The license is currently in its grace period if either it is a non-floating license, or it is a floating license with at least one hour remaining before expiration.

Last updated

Was this helpful?