I have a lot of application that has serial numbers. The first thing we need to care about it is to prevent to hack our serials numbers. the hackers are just like coders always search for repeated algorithms. in your case you just use the md5 algorithm and CPU ID to find a unique number as a serial number per any systems. But if the hacker knows about your algorithm, so he/she can make a tool to return any CPU Id+ md5.
This is my opinion to help you to clear the way.
First, you need to check the validity on application start. you can check it on Load and every time user Login events.
This is a sample
private void checkValidaty()
{
if (!setting.checkLicence(settingInfo.validateCode))
{
if (MessageBox.Show("Do you want to enter new licence?", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2, MessageBoxOptions.RightAlign) == DialogResult.No)
{
Application.Exit();
}
else
{
frmValidateNewLisence frm = new frmValidateNewLisence();
frm.ShowDialog();
this.checkValidaty();
}
}
}
Then you can call checkValidaty()
function on mentioned events.
Now I show you a sample to how to create a unique serial number.
As you did we have a method to GetProcessorID
private static string GetProcessorID()
{
string sProcessorID = "";
string sQuery = "SELECT ProcessorId FROM Win32_Processor";
ManagementObjectSearcher oManagementObjectSearcher = new ManagementObjectSearcher(sQuery);
ManagementObjectCollection oCollection = oManagementObjectSearcher.Get();
foreach (ManagementObject oManagementObject in oCollection)
{
sProcessorID = (string)oManagementObject["ProcessorId"];
}
return (sProcessorID);
}
You can ensure that there is the right id of any CPU.
Now with a password generator app, you can find an impressive static secret password. I just use this site to create strong passwords Secure Password Generator.
On this case, I use this one: y(M6dH%<Wx=)+fr,
.
After that, you need to send those password and CPUID to generateCode
function.
private static string generateCode(string GetProcessorID)
{
using (SHA1Managed sha1 = new SHA1Managed())
{
var hash = sha1.ComputeHash(Encoding.UTF8.GetBytes(Id));
var sb = new StringBuilder(hash.Length * 2);
foreach (byte b in hash)
{
// can be "x2" if you want lowercase
sb.Append(b.ToString("X2"));
}
return sb.ToString() + "y(M6dH%<Wx=)+fr," + GetProcessorID;
}
}
This Method generates a Non-repetitive
and Non-guessable
license.
The only weak point is being exposed your static password so you need to lock your source or other ways to secure it.