fix: 将MD5哈希算法替换为更安全的SHA256算法
This commit is contained in:
parent
d538527e7a
commit
c5aec7f463
@ -673,7 +673,7 @@ async def delete_user(
|
|||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
# 生成4位哈希(基于user_id保证唯一性)
|
# 生成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.is_deleted = 1
|
||||||
user.deleted_at = utc_now_naive()
|
user.deleted_at = utc_now_naive()
|
||||||
|
|||||||
@ -102,7 +102,7 @@ class UserRepository:
|
|||||||
if username:
|
if username:
|
||||||
import hashlib
|
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}"
|
user.username = f"已注销用户-{hash_suffix}"
|
||||||
if phone_number:
|
if phone_number:
|
||||||
user.phone_number = None
|
user.phone_number = None
|
||||||
|
|||||||
@ -47,7 +47,7 @@ def hashstr(input_string, length=None, with_salt=False, salt=None):
|
|||||||
salt = f"{time.time()}_{uuid.uuid4().hex[:8]}"
|
salt = f"{time.time()}_{uuid.uuid4().hex[:8]}"
|
||||||
encoded_string = (encoded_string.decode("utf-8") + salt).encode("utf-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:
|
if length:
|
||||||
return hash[:length]
|
return hash[:length]
|
||||||
return hash
|
return hash
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user