Creating nice BETA keys

I created a web application that will start to run a beta test soon. I would really like to pass beta offers and keys that look good.

i.e. A3E6-7C24-9876-235B

It is about 16 characters, hexadecimal digits. This is like a typical beta key that you can see. My question is what is the standard way to generate something like this and make sure that it is unique and that it will not be easy for someone to guess the beta key and create your own.

I have some ideas that will probably work for beta keys:

  • MD5 is safe enough for this, but it is long and ugly and can cause confusion between 0 and O, or 1 and l.
  • I could start with a large 16-digit hexadecimal number. So that people do not guess that the next beta key can increase the value by a random number each time. The range of numbers between 1111-1111-1111-1111 and eeee-eeee-eeee-eeee will have enough space to spare, even if I skip large numbers of numbers.

I think I'm just wondering if there is a standard way to do this that I don't find with Google. Is there a better way?

+3
source share
3 answers

" " - uuid. : ( 4) (, + ?) ( 3 5).

java, python .

PS , , , , - . "" ( + ). imho: " - - -wombat-cookie-" ( , , , ).

+3

(#, ):

private static readonly Random random = new Random(Guid.NewGuid().GetHashCode());

static void Main(string[] args)
{
    string x = GenerateBetaString();
}

public static string GenerateBetaString()
{
    const string alphabet = "ABCDEF0123456789";

    string x = GenerateRandomString(16, alphabet);

    return x.Substring(0, 4) + "-" + x.Substring(4, 4) + "-"
         + x.Substring(8, 4) + "-" + x.Substring(12, 4);
}

public static string GenerateRandomString(int length, string alphabet)
{
    int maxlen = alphabet.Length;
    StringBuilder randomChars = new StringBuilder(length);

    for (int i = 0; i < length; i++)
    {
        randomChars.Append(alphabet[random.Next(0, maxlen)]);
    }

    return randomChars.ToString();
}

:

97A8-55E5-C6B8-959E
8C60-6597-B71D-5CAF
8E1B-B625-68ED-107B
A6B5-1D2E-8D77-EB99
5595-E8DC-3A47-0605

. (), cryto (, ).

+3

Computing power is cheap, take your idea of ​​MD5 and do the β€œaesthetic” of your own design over the multitude. The code below creates almost instantly 2,000 unique keys that do not have a character in them 0,1,L,O. Change aestheticto match any additional criteria:

import random, hashlib

def potential_key():
    x = random.random()
    m = hashlib.md5()
    m.update(str(x))
    s = m.hexdigest().upper()[:16]
    return "%s-%s-%s-%s" % (s[:4],s[4:8],s[8:12],s[12:])

def aesthetic(s):
    bad_chars = ["0","1","L","O"]
    for b in bad_chars: 
        if b in s: return False
    return True

key_set = set()

while len(key_set) < 2000:
    k = potential_key()
    if aesthetic(k): 
        key_set.add(k)

print key_set

Key examples:

'4297-CAC6-9DA8-625A', '43DD-2ED4-E4F8-3E8D', '4A8D-D5EF-C7A3-E4D5', 
'A68D-9986-4489-B66C', '9B23-6259-9832-9639', '2C36-FE65-EDDB-2CF7', 
'BFB6-7769-4993-CD86', 'B4F4-E278-D672-3D2C', 'EEC4-3357-2EAB-96F5', 
'6B69-C6DA-99C3-7B67', '9ED7-FED5-3CC6-D4C6', 'D3AA-AF48-6379-92EF', ...
+1
source

All Articles