Demon

1075 palavras 5 páginas
I googled for sometime but i couldn't get what i want therefore i decided to write a Custom serial number generator class in C# .NET.

I try to figured out the method that return the following serial number format such as

SN = xxxx-xxxx-xxxx-xxxx-xxxx-xxxx

e.g : 85F7-1DF2-BB23-4C32-A684-C5D3 here's the one line of code : string serialNumber =
RandomSNKGenerator.GetSerialKeyAlphaNumaric(SNKeyLength.SN16);
or if you want to generate random number only : string serialNumberNumberOnly =
RandomSNKGenerator.GetSerialKeyNumaric(SNKeyNumLength.SN12);
Simple?

if you want to produce a complicated serial number key for your product, i think using
GetSerialKeyAlphaNumaric() method would be great. If you are very simple minded GetSerialKeyNumaric() still sufficient enough. :)

Here the class :

using System; using System.Collections.Generic; using System.Text;

namespace SNGenerator
{
public enum
SNKeyLength
{
SN16 = 16, SN20 = 20, SN24 = 24, SN28 = 28, SN32 = 32
}
public enum SNKeyNumLength
{
SN4= 4 , SN8 = 8, SN12 =
12
} public static class RandomSNKGenerator
{
private static string
AppendSpecifiedStr(int length, string str, char[] newKey)
{
string newKeyStr = ""; int k = 0; for (int i = 0; i < length; i++)
{
for
(k = i; k < 4 + i; k++)
{
newKeyStr += newKey[k];
}
if (k == length) { break; } else { i = (k) - 1; newKeyStr += str; }
}
return newKeyStr;
}
///

/// Generate standard serial key with alphanumaric format
///
/// the supported length of the serial key /// returns formated serial key public static string GetSerialKeyAlphaNumaric(SNKeyLength keyLength) {
Guid newguid = Guid.NewGuid(); string randomStr = newguid.ToString("N"); string tracStr = randomStr.Substring(0,
(int)keyLength);
tracStr = tracStr.ToUpper(); char[] newKey = tracStr.ToCharArray(); string newSerialNumber = ""; switch (keyLength
)
{ case SNKeyLength.SN16: newSerialNumber = AppendSpecifiedStr(16,
"-", newKey); break; case SNKeyLength.SN20: newSerialNumber =
AppendSpecifiedStr(20, "-", newKey);

Relacionados

  • demon
    847 palavras | 4 páginas
  • Demon
    600 palavras | 3 páginas
  • Demon Slayer
    498 palavras | 2 páginas
  • CANIS DEMON FICTICIO
    763 palavras | 4 páginas
  • 2 GAB Exerc Estr demon contab
    2793 palavras | 12 páginas
  • ARTE DEMONIACA
    2524 palavras | 11 páginas
  • Monster hunter
    387 palavras | 2 páginas
  • Recusos humanos
    709 palavras | 3 páginas
  • dark souls
    4632 palavras | 19 páginas
  • Student
    7568 palavras | 31 páginas