SDKs
...
Tutorials
Best Practices
License Checks
9min
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 c++ sdk configuration and usage docid\ mtxgbtqymb doqfxbcqop or getting started tutorial net 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 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 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 detect cheating with the system clock if cheating is detected, it will raise clocktamperedexception (c++) or datetimecheatingexception ( net) ensure that the license belongs to the device if the license doesn't belong to the device, it will raise devicenotlicensedexception 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 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();var license = licensemanager currentlicense(); license localcheck(); swift try license localcheck()manager = licensemanager(conf) license = manager load license() license local check() // go sdk v2 	license data, check resp, err = lh localcheck(true) 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();license check();licensemanager checklicense( license ); swift try license fullcheck()license check() // go sdk v2 	license data, err = lh checklicense(ctx) 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( license >dayspassedsincelastcheck() >= 3 ) license >check();if( license dayspassedsincelastcheck() >= 3 ) license check(); swift if date() timeintervalsince(linense lastsyncdate) > 24 60 60 { // 1 day try license fullcheck() }if license days since last check() >= 3 license check() 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 auto allowedperiodwithoutcheck = 7;//allow a week of usage without connection try { license >check(); return true;//continue after successful check } catch( const licensespringexception& ex ) { auto code = ex getcode(); if( code == enointerneterror || code == enetworktimeouterror || code == eservererror ) return license >dayspassedsincelastcheck() < allowedperiodwithoutcheck; //stop if the app is offline or cannot connect to the server longer than the allowed period return false;//stop in case of other exceptions }var allowedperiodwithoutcheck = 7;//allow a week of usage without connection try { license check(); return true;//continue after successful check } catch( licensespringexception ex ) { if( ex is networkexception || ex is licenseserverexception ) return license dayspassedsincelastcheck() < allowedperiodwithoutcheck; //stop if the app is offline or cannot connect to the server longer than the allowed period return false;//stop in case of other exceptions } 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 do not confuse grace period and subscription grace period to learn more about the subscription grace period, see subscription docid\ o79gcxoa72yqlyjl3bbhq by default grace period is 48 hours you can set another value using licensespring extendedoptions options; options setgraceperiod( 24 );//set 24 hours options setgraceperiod( 0 );//disable grace periodvar options = new licensespring extendedoptions(); options graceperiod = 24;//set 24 hours options graceperiod = 0;//disable grace periodconf = configuration(product="your product key",api key="your api key", shared key="your shared key",file key=key,file iv=iv, grace period conf=24) // go sdk v2 lm config = license manager licensemanagerbasicconfiguration{ 	 oauth false, 	 apikey "your api key", 	 sharedkey "your shared key", 	 productcode "your product code", 	 authdata auth fromkey("license key"), 	 } lm, = license manager newlicensemanager( lm config, license manager withgraceperiod(24), ) cfg manager = lm lh, = license handler newlicensehandler(cfg) the license class has methods to check if the grace period started and get the grace period end date license >check(); if( license >isgraceperiodstarted() ) std cout << "grace period started " << license >graceperiodhoursremaining() << " hours till the end of grace period ";license check(); if( license isgraceperiodstarted() ) console writeline( "grace period started {0} hours till the end of grace period ", license graceperiodhoursremaining() );license check() if license is grace period started() print("grace period hours remaining ",license grace period hours remaining())// go sdk v2 if license data isgraceperiodstarted() fmt println("grace period started at ",license data graceperiodstartdate) the grace period starts when one of the covered requests fails and resets after a successful request for cloud floating licenses with a grace period, the exceptions on online checks will be ignored only if more than an hour of the floating period remains