This repository has been archived on 2021-09-15. You can view files and clone it, but cannot push or open issues or pull requests.
M2OLA/backend/app/utils.py

16 lines
343 B
Python
Raw Normal View History

2017-01-23 14:50:05 +00:00
import random
import string
from hashlib import sha512
SIMPLE_CHARS = string.ascii_letters + string.digits
2017-01-23 14:50:20 +00:00
def get_random_string(length=32):
2017-01-23 14:50:05 +00:00
return ''.join(random.choice(SIMPLE_CHARS) for i in range(length))
2017-01-23 14:50:20 +00:00
def get_random_hash(length=64):
2017-01-23 14:50:05 +00:00
hash = sha512()
hash.update(get_random_string())
return hash.hexdigest()[:length]