Support
Joined: 18 Jul 2005 Posts: 731
|
Posted: Mon Jun 01, 2009 7:48 am Post subject: INFO: How to validate serials from your software |
|
|
Serials are short cryptographically secure codes in the following form: "63RTV-VCEUD-04CU1-NPU5P-MDHVS-HAVXU-V"
The only reason to use serial codes instead of license codes is because they are short and this can be easily entered by the user. However, a serial code cannot be validated on its own, so using a serial code requires a one time communication with a license service to retrieve a license code against that serial.
To use serials in your software, you must use the CCryptoLicense.GetLicenseFromSerial function which connects with the license service to retrieve the license against that serial. If this method succeeds, you can proceed to validate the license using the CCryptoLicense.GetStatus function.
Normally, your licensing scheme will use either serials or licenses, however you can also give serials to some users and licenses to others; in this case, you will need to differentiate between them. The following code shows how to do this:
[C++]
Code: | CString licOrSerial = _T("<<serial or license>>"); // may be entered by user
CCryptoLicense* lic = new CCryptoLicense(_T("<<validation key for your project>>"));
lic->SetLicenseServiceURL(_T("<<URL of your license service>>"));
// Try to validate serial and retrieve license against the serial
SerialValidationResult result = lic->GetLicenseFromSerial(licOrSerial);
if (result == SVR_Failed)
{
// 'licOrSerial' is in serial form but validation of serial failed
AfxMessageBox(_T("Serial Validation Failed"));
return;
}
else if (result == SVR_NotASerial)
{
// 'licOrSerial' is not a serial but may be a license, set lic.LicenseCode and validate it
lic->SetLicenseCode(licOrSerial);
}
else //if (result == SVR_Success)
{
// CCryptoLicense.GetLicenseFromSerial set the license code with the retrieved license code
// validate it
}
// Validate license by querying Status property
if (lic->GetStatus() != LS_Valid)
{
AfxMessageBox(_T("License Validation Failed"));
return;
} |
|
|