View previous topic :: View next topic |
Author |
Message |
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Wed Jun 06, 2007 4:02 pm Post subject: Embedding product info in license key |
|
|
I've generated a license for a user. It is registered in their name. The product has embedded product info, which is called "PRO". I only use it to restrict certain features. When the install license form appears (from the sample app), it gets to this line:
if (Valid_license(license, form.LicensedTo))
and that method goes here:
private bool Valid_license(EncryptedLicense _license, string _licensedTo)
{
if (_license.ProductInfo.Length < 2) return false;
string checksum = _license.ProductInfo.Substring(1);
string hold = EncryptedLicense.Checksum(_licensedTo);
return checksum.Equals(hold);
}
checksum equals 1816 without using SubString(1). It will equal 816 with SubString(1). I have to use SubString(1) since hold is also 816. Is all of that correct? Shouldn't I use the full four digits?
If _license.ProductInfo is returning the encoded user name, how do I access the embedded info for "PRO" to restrict features? Maybe I've set the product license or user license up incorrectly.
Thanks,
Brett |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Thu Jun 07, 2007 10:41 pm Post subject: |
|
|
In the CustomLicensedApp sample project two pieces of information are encoded into the ProductInfo. The first is always 1 character long and is the number of processors. The second is the checksum on the customer name. This starts at character 2 hence the use of SubString(1).
If you are only embedding the checksum then you don't need to use the SubString(1) call. If you want to include the information about Standard/Pro then you could use the first character of the product info for that eg P1816 or S1816. Using a single character "P" instead of "PRO" will give you shorter license keys. Then you would use the SubString(1). _________________ Infralution Support |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Sun Jun 10, 2007 5:00 pm Post subject: |
|
|
Perfect! Thanks for explaining. |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Sun Jun 10, 2007 5:56 pm Post subject: |
|
|
I guess I'm still not getting this. The conditional would fail for non PRO users but now I see it fails for PRO users as well. I have Product Info for "P" for a specific user. I validate the license belongs to that user. Here's what I do when checking if they are using the PRO version:
string checksum = _license.ProductInfo.Substring(0,1);
if(checksum.equals(Infralution.Licensing.EncryptedLicense.Checksum("P")))
//valid PRO version
else
//using Standard version
The checksum == 1. The checksum on "P" is 653. That will always fail. If I use Substring(1), the checksum == 648, which will also fail. What am I doing wrong? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jun 11, 2007 12:41 am Post subject: |
|
|
The check for standard or pro version does not require a checksum. The code should be simply:
Code: | string edition = _license.ProductInfo.Substring(0,1);
if (edition == "P")
// pro version
else if (edition == "S")
// standard version
else
// this is an error |
The checksum technique is only used when you want your license to be keyed to some data (eg customer name) which itself is too long to embed in the ProductInfo without making the license key excessively long. In this case you take a checksum of the original data (customer name) and embed the 3 character checksum in your license key. Then when you check the license you get the customer to enter their name and verify that the checksum on the entered data matches the checksum in the license key. _________________ Infralution Support |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Mon Jun 11, 2007 1:54 am Post subject: |
|
|
The problem is that ProductInfo is something numeric. When I look at the licenses generated in License Tracker, for the PRO versions, I see the licensed names and product info. But even the basic version, which I don't enter in ProductInfo for, do have numeric ProductInfo:
Pro Guy 2 - 1537
Pro Guy - 161
Basic Guy - 1372
If I pull the first character out of ProductInfo, it's a one. As you can see, that's not useful for comparing which version they are using. It would be nice to use the comparison you mentioned against "P" but I don't get that. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jun 11, 2007 3:31 am Post subject: |
|
|
How are you generating your license keys? Are you using a custom generator with license tracker to set the ProductInfo? If so you will need to change the custom generator to generate the ProductInfo correctly (with the P or S as the first character of the ProductInfo).
Your custom generator should provide a form to allow you to select the Pro or Standard version and enter the customers name. Then based on this your ProductInfo logic would be something like:
Code: | string productInfo = null;
if (proRadioButton.Checked)
productInfo = "P";
else
productInfo = "S";
productInfo += EncryptedLicense.Checksum(customerText.Text); |
_________________ Infralution Support |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Mon Jun 11, 2007 5:19 am Post subject: |
|
|
I'm not using a custom generator (I don't think) to generate a licenses. I click the Generate License Keys button in License Tracker. That pops up a form. I select the product and distributor. For Product Info, I enter in "P" and select to generate one key. Another popup appears. I enter in the customer name.
I don't see where to change the way licenses are generated. You said to generate them correctly but I'm not sure what you mean.
For the product, I use:
- Key Strength: 7
- Include Product Info Checksum
- No default product info
- Customer Generator: CustomerGenerator.MyGenerator.CustomerGenerator
If I switch to Infralution.LicenseTracker.NamechecksumGenerator.LicenseTracker
the keys generatored don't allow licensing to a user. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jun 11, 2007 8:13 am Post subject: |
|
|
Quote: | Customer Generator: CustomerGenerator.MyGenerator.CustomerGenerator |
This means you are using a custom generator. You must have compiled the sample Custom Generator project and installed the DLL in the License Tracker dll. It is this custom generator that displays the form where you are entering the customer name. Normally when using a custom generator you would tick the "Generate Keys at Point of Sale" option for the product. Then when you create a sale you can generate a key for the customer (and extract the customer name automatically).
When you use a custom generator it determines the ProductInfo. In ealier releases you could enter the ProductInfo when using the "Generate License Keys" button - but this value was ignored if a custom generator was installed. In the latest release if a custom generator is installed you don't see the ProductInfo field (which is less confusing).
You need to modify the sample custom generator to include radio buttons in the form to select your Pro/Standard version. Then generate the ProductInfo as indicated in the earlier post. _________________ Infralution Support |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Mon Jun 11, 2007 3:10 pm Post subject: |
|
|
I've modified the CustomerGenerator_CS app to include product info via textbox, just to give me more options on what I can use as product info. I placed this DLL in the c:\Program Files\Infralution\Infralution Licensing System\License Tracker folder. The help says to place it with the EXE in the bin folder but there isn't a bin folder. I click to edit my product and type in the DLL namespace - CustomerGenerator.MyGenerator. I get this message when I click OK:
The type name (CustomerGenerator.MyGenerator) could not be resolved to a valid type. Ensure the DLL contain the type is placed the same directory as the License Tracker executable. I also placed the DLL in c:\Program Files\Infralution\Infralution Licensing System\bin but get the same message. This is the project that came with my install so LicenseTracker.API.dll is referenced. |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Mon Jun 11, 2007 10:27 pm Post subject: |
|
|
It looks like maybe you haven't specified the full name of the type (including the DLL name). If you haven't renamed the sample project or class then the full type name should be:
Code: | CustomGenerator.MyGenerator, CustomGenerator |
This is what you should enter in the Custom Generator field for the product. _________________ Infralution Support |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Tue Jun 12, 2007 12:14 am Post subject: |
|
|
Thanks - that was the problem. I've also modified the Substring(1) to Substring(1,1) since the name is pushed to the right to make space for the version letter. I've left the processor number as the first character.
How can I clear out a license once it is entered so that I can continue testing different versions with different names?
Thanks,
Brett |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jun 12, 2007 8:41 am Post subject: |
|
|
Quote: | I've left the processor number as the first character. |
Unless you actually have different license prices for multi-processors then you may as well delete this (and remove the updown control). The CustomGenerator project is only a sample - showing what you can do.
Quote: | How can I clear out a license once it is entered so that I can continue testing different versions with different names? |
You can simply delete the ".lic" file. _________________ Infralution Support |
|
Back to top |
|
|
brettr
Joined: 09 Apr 2007 Posts: 16
|
Posted: Tue Jun 12, 2007 3:25 pm Post subject: |
|
|
I'm running the app in debug mode of VS.NET 2005. I don't have a lic file in bin/debug or the root app folder. Where would the file be located? |
|
Back to top |
|
|
Infralution
Joined: 28 Feb 2005 Posts: 5027
|
Posted: Tue Jun 12, 2007 10:30 pm Post subject: |
|
|
Depends on what you specified for the "_licenseFile" parameter when you called GetLicense:
Code: | EncryptedLicense license = provider.GetLicense(LICENSE_PARAMETERS, _licenseFile); |
In the latest release of ILS the sample projects illustrate setting the licenseFile parameter to store the license key in the common data directory.
Code: | static string _dataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);
static string _licenseFile = _dataDir + @"\LicensedApp\LicensedApp.lic"; |
The windows path for this is:
Code: | C:\Documents and Settings\All Users\Application Data\LicensedApp\LicensedApp.lic |
You should obviously change the name of the license file and the sub directory to match you own needs and application name.
In earlier releases the sample projects saved the license file in the executable directory by default. _________________ Infralution Support |
|
Back to top |
|
|
|