fix: 将MD5哈希算法替换为更安全的SHA256算法

This commit is contained in:
Wenjie Zhang 2026-01-22 12:55:57 +08:00
parent d538527e7a
commit c5aec7f463
3 changed files with 3 additions and 3 deletions

View File

@ -673,7 +673,7 @@ async def delete_user(
import hashlib
# 生成4位哈希基于user_id保证唯一性
hash_suffix = hashlib.md5(user.user_id.encode()).hexdigest()[:4]
hash_suffix = hashlib.sha256(user.user_id.encode()).hexdigest()[:4]
user.is_deleted = 1
user.deleted_at = utc_now_naive()

View File

@ -102,7 +102,7 @@ class UserRepository:
if username:
import hashlib
hash_suffix = hashlib.md5(user.user_id.encode()).hexdigest()[:4]
hash_suffix = hashlib.sha256(user.user_id.encode()).hexdigest()[:4]
user.username = f"已注销用户-{hash_suffix}"
if phone_number:
user.phone_number = None

View File

@ -47,7 +47,7 @@ def hashstr(input_string, length=None, with_salt=False, salt=None):
salt = f"{time.time()}_{uuid.uuid4().hex[:8]}"
encoded_string = (encoded_string.decode("utf-8") + salt).encode("utf-8")
hash = hashlib.md5(encoded_string).hexdigest()
hash = hashlib.sha256(encoded_string).hexdigest()
if length:
return hash[:length]
return hash