To be able to generate licenses your project needs to reference the following assemblies
- Habanero.Licensing.Shared
- Habanero.Licensing.Generator
The easiest setup is to create a new Web Project or Site and add new Web Form for creating licenses. The web form does not need to return anything other than an empty page if you are sending the license directly in an email. In the scenario just create the license in the Page_load method.
The following code is a generic example in C#:
- byte[] applicationSecret = Convert.FromBase64String("YOURSECRET");
- private string privateKey = "YOUR_PRODUCTS_PRIVATE_KEY";
- private string thisLicense = @"YOUR_OWN_LICENSE_STRING_FOR_THE_LICENSE_MANAGER";
- protected void Page_Load(object sender, EventArgs e)
- {
- //get user data
- string email = Request.Form["email"];
- string fullname = Request.Form["fullname"];
- string company = Request.Form["company"];
- Guid userSerial = Guid.NewGuid();
- LicensedUser licensee = null;
- //depending on what info you expect to receive you may need to call a differnt create method
- licensee = LicensedUser.Create(fullname.Trim(), email.Trim(), company.Trim());
- var product = new LicensedProductInformation();
- product.ProductName = "YOURPRODUCTNAME";
- //set the maxversion to the version you will be issuing licenses for
- //the following line issues licenses for *.*
- product.MaxVersion = new LicensedVersionNumber();
- //Set the edition the license is valid for
- product.LicenseName = "YOUREDITION";
- //set the expiration date or null
- DateTime? expiration = DateTime.Now.AddYears(1);
- //now create the actual license
- var license = LicenseGenerator.CreateLicense(thisLicense, new ByteHolder(privateKey), applicationSecret,
- product, userSerial,
- licensee,
- expiration);
- //pad the license using ===== to make it clear in emails
- string emailBody =
- "You have purchased a license - your license is included in this email:\n" +
- "\n==========\n" + license.ToString() + "\n==========";
- var mailer = new System.Net.Mail.SmtpClient("smtp.yourserver.com")
- {
- UseDefaultCredentials = false,
- Credentials =
- new NetworkCredential("user", "password"),
- DeliveryMethod = SmtpDeliveryMethod.Network,
- Timeout = 50000
- };
- var message = new MailMessage("[email protected]", email, "Your License to PRODUCTNAME",
- emailBody
- );
- //send a copy to yourself just in case
- message.Bcc.Add("[email protected]");
- mailer.Send(message);