django-vue-admin/backend/dvadmin/utils/string_util.py

43 lines
900 B
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# -*- coding: utf-8 -*-
"""
@author: 猿小天
@contact: QQ:1638245306
@Created on: 2021/8/21 021 9:48
@Remark:
"""
import hashlib
import random
CHAR_SET = ("2", "3", "4", "5",
"6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
"J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V",
"W", "X", "Y", "Z")
def random_str(number=16):
"""
返回特定长度的随机字符串(非进制)
:return:
"""
result = ""
for i in range(0, number):
inx = random.randint(0, len(CHAR_SET) - 1)
result += CHAR_SET[inx]
return result
def has_md5(str, salt='123456'):
"""
md5 加密
:param str:
:param salt:
:return:
"""
# satl是盐值默认是123456
str = str + salt
md = hashlib.md5() # 构造一个md5对象
md.update(str.encode())
res = md.hexdigest()
return res