pythonsalt-cryptographybase62

Creating a salt in python


How would I create a random, 16-character base-62 salt in python? I need it for a protocol and I'm not sure where to start. Thanks.


Solution

  • >>> import random
    >>> ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
    >>> chars=[]
    >>> for i in range(16):
        chars.append(random.choice(ALPHABET))
    
    >>> "".join(chars)
    'wE9mg9pu2KSmp5lh'
    

    This should work.