add:解决select可跳过次数限制,新增sha256加密token,限制取件码+ip+时间999s内取件

This commit is contained in:
lan
2023-02-08 03:17:22 +08:00
parent f4f40e245a
commit 1f303d3340
2 changed files with 16 additions and 5 deletions
+7
View File
@@ -1,6 +1,9 @@
import datetime
import hashlib
import random
import asyncio
import time
from sqlalchemy import or_, select, delete
from sqlalchemy.ext.asyncio.session import AsyncSession
from .database import Codes, engine
@@ -41,3 +44,7 @@ async def get_code(s: AsyncSession):
while (await s.execute(select(Codes.id).where(Codes.code == code))).scalar():
code = random.randint(10000, 99999)
return str(code)
async def get_token(ip, code):
return hashlib.sha256(f"{ip}{code}{int(time.time()) / 1000}000{settings.SECRET_KEY}".encode()).hexdigest()