mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
39 lines
849 B
Python
39 lines
849 B
Python
# coding=utf-8
|
||
"""
|
||
@project: MaxKB
|
||
@Author:虎虎
|
||
@file: common.py
|
||
@date:2025/4/14 18:23
|
||
@desc:
|
||
"""
|
||
import hashlib
|
||
from typing import List
|
||
|
||
|
||
def password_encrypt(row_password):
|
||
"""
|
||
密码 md5加密
|
||
:param row_password: 密码
|
||
:return: 加密后密码
|
||
"""
|
||
md5 = hashlib.md5() # 2,实例化md5() 方法
|
||
md5.update(row_password.encode()) # 3,对字符串的字节类型加密
|
||
result = md5.hexdigest() # 4,加密
|
||
return result
|
||
|
||
|
||
def group_by(list_source: List, key):
|
||
"""
|
||
將數組分組
|
||
:param list_source: 需要分組的數組
|
||
:param key: 分組函數
|
||
:return: key->[]
|
||
"""
|
||
result = {}
|
||
for e in list_source:
|
||
k = key(e)
|
||
array = result.get(k) if k in result else []
|
||
array.append(e)
|
||
result[k] = array
|
||
return result
|