You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
473 B

4 years ago
import jwt
def generate_jwt(username):
# https://www.jianshu.com/p/03ad32c1586c
headers = {
"alg": "HS256",
"typ": "JWT"
}
salt = "acvv"
payload = {
"name": username
}
token = jwt.encode(payload=payload, key=salt, algorithm='HS256', headers=headers).decode('utf-8')
return token
4 years ago
def check_jwt(cookie_jwt):
salt = "acvv"
info = jwt.decode(cookie_jwt, salt, True, algorithm='HS256')
return info['name']