Simple Software Licensing
            Help Center Simple Software Licensing General

            Generate Licenses From Code

            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#: 

            1.         byte[] applicationSecret = Convert.FromBase64String("YOURSECRET");
            2.         private string privateKey = "YOUR_PRODUCTS_PRIVATE_KEY";
            3.         private string thisLicense = @"YOUR_OWN_LICENSE_STRING_FOR_THE_LICENSE_MANAGER";
            4.         protected void Page_Load(object sender, EventArgs e)
            5.         {
            6.             //get user data
            7.             string email = Request.Form["email"];
            8.             string fullname = Request.Form["fullname"];
            9.             string company = Request.Form["company"];
            10.             Guid userSerial = Guid.NewGuid();

            11.             LicensedUser licensee = null;

            12.             //depending on what info you expect to receive you may need to call a differnt create method
            13.             licensee = LicensedUser.Create(fullname.Trim(), email.Trim(), company.Trim());

            14.             var product = new LicensedProductInformation();
            15.             product.ProductName = "YOURPRODUCTNAME";
            16.             //set the maxversion to the version you will be issuing licenses for
            17.             //the following line issues licenses for *.*
            18.             product.MaxVersion = new LicensedVersionNumber();
            19.             //Set the edition the license is valid for
            20.             product.LicenseName = "YOUREDITION";

            21.             //set the expiration date or null
            22.             DateTime? expiration = DateTime.Now.AddYears(1);

            23.             //now create the actual license
            24.             var license = LicenseGenerator.CreateLicense(thisLicense, new ByteHolder(privateKey), applicationSecret,
            25.                                                             product, userSerial,
            26.                                                             licensee,
            27.                                                             expiration);
            28.             //pad the license using ===== to make it clear in emails
            29.             string emailBody =
            30.                "You have purchased a license - your license is included in this email:\n" +
            31.                "\n==========\n" + license.ToString() + "\n==========";

            32.             var mailer = new System.Net.Mail.SmtpClient("smtp.yourserver.com")
            33.             {
            34.                 UseDefaultCredentials = false,
            35.                 Credentials =
            36.                     new NetworkCredential("user", "password"),
            37.                 DeliveryMethod = SmtpDeliveryMethod.Network,
            38.                 Timeout = 50000
            39.             };

            40.             var message = new MailMessage("[email protected]", email, "Your License to PRODUCTNAME",
            41.                                                  emailBody
            42.                        );
            43.             //send a copy to yourself just in case
            44.             message.Bcc.Add("[email protected]");
            45.             mailer.Send(message);

            Updated: 08 Nov 2017 10:04 PM
            Helpful?  
            Help us to make this article better
            0 0