在线实习管理平台中学生安全与技术实现
import hashlib
def hash_password(password):
return hashlib.sha256(password.encode()).hexdigest()
# 示例:hash_password("student123")
from flask_jwt_extended import create_access_token, jwt_required, get_jwt_identity
from flask import Flask, jsonify, request
app = Flask(__name__)
app.config['JWT_SECRET_KEY'] = 'super-secret-key'
@app.route('/login', methods=['POST'])
def login():
username = request.json.get('username')
password = request.json.get('password')
if username == "student" and password == "123":
access_token = create_access_token(identity=username)
return jsonify(access_token=access_token), 200
return jsonify({"msg": "Invalid credentials"}), 401
@app.route('/profile', methods=['GET'])
@jwt_required()
def profile():
current_user = get_jwt_identity()
return jsonify(logged_in_as=current_user), 200
本站知识库部分内容及素材来源于互联网,如有侵权,联系必删!