django_project_demo/app/utils/encrypt.py
2024-08-24 03:25:23 +00:00

14 lines
387 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
对密码进行md5加密
"""
import hashlib
from django.conf import settings # 要用到settings.py文件中的SECRET_KEY字符串对产生的md5加密字符串加盐
def md5(data_string):
salt = settings.SECRET_KEY
# 对产生的md5加密字符串加盐
obj = hashlib.md5(salt.encode('utf-8'))
obj.update(data_string.encode('utf-8'))
return obj.hexdigest()