# -*- coding: utf-8 -*-
from passlib.apps import custom_app_context as pwd_context
import config
import MySQLdb,datetime
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer, BadSignature, SignatureExpired
class QXPasswd(object):
def __init__(self, password):
self.password = password
def generate_password(self):
password_hash = pwd_context.encrypt(self.password)
return password_hash
def verify_password(self, password_hash):
return pwd_context.verify(self.password, password_hash)
class QXToken(object):
def __init__(self, name):
self.name = name
def generate_auth_token(self, expiration = 3600):
s = Serializer(config.SECRET_KEY, expires_in = expiration)
return s.dumps({'name': self.name })
def verify_auth_token(self, token):
s = Serializer(config.SECRET_KEY)
try:
data = s.loads(token)
except Signature
python 数据加密以及生成token和token验证——pwd_context.encrypt()
最新推荐文章于 2023-08-02 19:17:51 发布