How to create serial number generator? [closed]
How can I program a Serial Number Generator that generates serial numbers for some existing software?
You don't state any specific requirements but you can use a GUID.
Guid mySerialNumber = Guid.NewGuid();
I have used this CodeProject Article before when I've needed to do the same thing for projects I have worked on recently. I found it very detailed and while I didn't use everything in the sample I did get a lot out of it. (I have no affiliation with CodeProject or the author)
Additionally there is a library which gives you all this functionality complete with license file replacement and heaps of other features, but its not free, and unfortunately I couldn't remember the link. I'm sure a bit of Googgling and you'll find it.
public static string GetSerialKeyAlphaNumaric(SNKeyLength keyLength)
{
string newSerialNumber = "";
string SerialNumber=Guid.NewGuid().ToString("N").Substring(0, (int)keyLength).ToUpper();
for(int iCount=0; iCount < (int) keyLength ;iCount +=4)
newSerialNumber = newSerialNumber + SerialNumber.Substring(iCount, 4) + "-";
newSerialNumber = newSerialNumber.Substring(0, newSerialNumber.Length - 1);
return newSerialNumber;
}
Try a number you can test using Luhn's algorithm. That way, you can make it long an inscrutable, yet still easily confirmed. The article contains a link to a C# implementation.
精彩评论