How to Generate Serial Key in C#
By Tan Lee Published on Jul 03, 2017 10.42K
The SKGL is a lightweight .NET library that simplifies these processes. This article explains how to implement serial key generation and validation using SKGL in a Windows Forms application.
How to Implement Serial Key Generation and Validation Using SKGL Library?
Open Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "SerialKeyDemo" and then click OK
Right click on your project select Manage NuGet Packages -> Search SoftwareProtector -> Install
Software Protector is an open source 100% managed .NET licensing system based on SKGL Project. Generate keys for your software, and validate them using SKGL library in your own project.
Design your form as shown below.
The btnGenerate_Click
event handler uses the SKGL.Generate
class to create a serial key. This key is based on a secret phrase and the number of valid days provided by the user.
private void btnGenerate_Click(object sender, EventArgs e) { // Generate a serial key SKGL.Generate generate = new SKGL.Generate(); generate.secretPhase = txtPassword.Text; // Secret phrase from user input txtSerial.Text = generate.doKey(Convert.ToInt32(txtDay.Text)); // Generate the key }
The btnValid_Click
event handler uses the SKGL.Validate
class to verify the serial key. It checks the key’s validity and provides details like the creation date, expiration date, and remaining valid days.
private void btnValid_Click(object sender, EventArgs e) { // Validate the serial key SKGL.Validate validate = new SKGL.Validate(); validate.secretPhase = txtPassword.Text; // Secret phrase used during key generation validate.Key = txtSerial.Text; // Serial key to validate txtStatus.Text = "Creation date: " + validate.CreationDate + "\r\n" + "Expire date: " + validate.ExpireDate + "\r\n" + "Day left: " + validate.DaysLeft; }
VIDEO TUTORIAL
- How to Open and Show a PDF file in C#
- How to Get all Forms and Open Form with Form Name in C#
- How to zoom an image in C#
- How to Print a Picture Box in C#
- How to update UI from another thread in C#
- How to Search DataGridView by using TextBox in C#
- How to read and write to text file in C#
- How to save files using SaveFileDialog in C#