|
@@ -16,6 +16,7 @@ import datetime
|
|
|
import time
|
|
|
from pathlib import Path
|
|
|
from random import Random
|
|
|
+import base64
|
|
|
import ipdb
|
|
|
import simplejson as json
|
|
|
from django.core import serializers
|
|
@@ -42,5 +43,62 @@ class CommonService:
|
|
|
str += characterSet[random.randint(0, length)]
|
|
|
return str
|
|
|
|
|
|
+ # 加密
|
|
|
+ # @staticmethod
|
|
|
+ def encrypt_pwd(self, userPwd):
|
|
|
+ for i in range(1, 4):
|
|
|
+ if i == 1:
|
|
|
+ userPwd = self.RandomStr(3, False)+userPwd+self.RandomStr(3, False)
|
|
|
+ userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
|
+ if i == 2:
|
|
|
+ userPwd = self.RandomStr(2, False)+str(userPwd)+self.RandomStr(2, False)
|
|
|
+ userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
|
+ if i == 3:
|
|
|
+ userPwd = self.RandomStr(1, False)+str(userPwd)+self.RandomStr(1, False)
|
|
|
+ userPwd = base64.b64encode(str(userPwd).encode("utf-8")).decode('utf8')
|
|
|
+ return userPwd
|
|
|
+
|
|
|
+ # 解密
|
|
|
+ @staticmethod
|
|
|
+ def decode_pwd(password):
|
|
|
+ for i in range(1, 4):
|
|
|
+ if i == 1:
|
|
|
+ # 第一次先解密
|
|
|
+ password = base64.b64decode(password)
|
|
|
+ password = password.decode('utf-8')
|
|
|
+ # 截去第一位,最后一位
|
|
|
+ password = password[1:-1]
|
|
|
+ if i == 2:
|
|
|
+ # 第2次先解密
|
|
|
+ password = base64.b64decode(password)
|
|
|
+ password = password.decode('utf-8')
|
|
|
+ # 去前2位,后2位
|
|
|
+ password = password[2:-2]
|
|
|
+ if i == 3:
|
|
|
+ # 第3次先解密
|
|
|
+ password = base64.b64decode(password)
|
|
|
+ password = password.decode('utf-8')
|
|
|
+ # 去前3位,后3位
|
|
|
+ password = password[3:-3]
|
|
|
+ return password
|
|
|
+
|
|
|
+ # 生成随机字符串
|
|
|
+ @staticmethod
|
|
|
+ def RandomStr(randomlength=8, number=False):
|
|
|
+ str = ''
|
|
|
+ if number == False:
|
|
|
+ characterSet = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsT' \
|
|
|
+ 'tUuVvWwXxYyZz0123456789'
|
|
|
+ else:
|
|
|
+ characterSet = '0123456789'
|
|
|
+
|
|
|
+ length = len(characterSet) - 1
|
|
|
+
|
|
|
+ random = Random()
|
|
|
+ for index in range(randomlength):
|
|
|
+ str += characterSet[random.randint(0, length)]
|
|
|
+
|
|
|
+ return str
|
|
|
+
|
|
|
# data = CommonService.encrypt_data(20)
|
|
|
# print(data)
|