Files
B42/at_django_boilerplate/utils/hash_utils.py
2026-01-07 12:09:20 +05:30

19 lines
391 B
Python
Executable File

import hashlib
from hashids import Hashids
from django.conf import settings
def hexdigest(text):
text_hash = hashlib.sha256(text.encode()).hexdigest()
return text_hash
HASHIDS = Hashids(salt=settings.SECRET_KEY, min_length=12) # or 8
def encode_id(pk):
return HASHIDS.encode(pk)
def decode_slug(slug):
return HASHIDS.decode(slug)[0] if HASHIDS.decode(slug) else None