use hashes of approximately 80 bit and use all digits and characters (lower case) for the hash

This commit is contained in:
lars 2010-04-26 01:13:15 +00:00
parent fc4ff978cc
commit 8eda09bb20

View file

@ -178,10 +178,22 @@ def get_poll_admin_id(hash_key):
else: else:
return None return None
def get_new_hash_key(): def get_new_hash_key(length=16, charset=None):
hash_key = uuid.uuid4().get_hex() """ returns a quite random hash key with the specified length """
if charset is None:
charset = "0123456789abcdefghijklmnopqrstuvwxyz"
def get_hash_string(length):
base = uuid.uuid4().int
result = []
while len(result) < length:
value = base % len(charset)
base //= len(charset)
result.append(charset[value])
return "".join(result)
# repeat the hash generation until a new value is found
hash_key = get_hash_string(length)
while (not get_poll_id(hash_key) is None) or (not get_poll_admin_id(hash_key) is None): while (not get_poll_id(hash_key) is None) or (not get_poll_admin_id(hash_key) is None):
hash_key = uuid.uuid4().get_hex() hash_key = get_hash_string(length)
return hash_key return hash_key
@bobo.query('/polls/new') @bobo.query('/polls/new')