Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

🩹(backend) fix identity hash randomness

lebaudantoine053c4a40e96d
diff --git a/src/backend/core/utils.py b/src/backend/core/utils.py
index a4c67792..304b5de7 100644
--- a/src/backend/core/utils.py
+++ b/src/backend/core/utils.py
@@ -4,6 +4,7 @@ Utils functions used in the core app
# ruff: noqa:S311
+import hashlib
import json
import random
from typing import Optional
@@ -24,7 +25,11 @@ def generate_color(identity: str) -> str:
range and ensure predictability.
"""
- random.seed(hash(identity))
+ # ruff: noqa:S324
+ identity_hash = hashlib.sha1(identity.encode("utf-8"))
+ # Keep only hash's last 16 bits, collisions are not a concern
+ seed = int(identity_hash.hexdigest(), 16) & 0xFFFF
+ random.seed(seed)
hue = random.randint(0, 360)
saturation = random.randint(50, 75)
lightness = random.randint(25, 60)