From f66bca67ac79c6d158a566ea169552194c64bd66 Mon Sep 17 00:00:00 2001 From: thecookingsenpai Date: Fri, 2 Feb 2024 16:31:18 +0100 Subject: [PATCH] Testing with SHA1 gives positive results, also changed the truncation rule --- app/utils/hashing.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/utils/hashing.py b/app/utils/hashing.py index 5631f480..e9ed147d 100644 --- a/app/utils/hashing.py +++ b/app/utils/hashing.py @@ -34,4 +34,9 @@ def create_hash(*args: str, decode=False, limit=10) -> str: str_ = str_.encode("utf-8") str_ = hashlib.sha1(str_).hexdigest() # REVIEW Switched to sha1 hashlib.sha256(str_).hexdigest() - return str_[-limit:] + + # REVIEW Take the first limit/2 and last limit/2 characters + # This is to avoid collisions + return str_[:limit // 2] + str_[-limit // 2:] if limit % 2 == 0 else str_[:limit // 2] + str_[-limit // 2 - 1:] + + # return str_[-limit:]