PythonAuthentication & cryptographyDifficulty 2/3
import hashlib
from flask import request, jsonify
@app.post("/login")
def login():
email = request.json["email"]
password = request.json["password"]
user = db.find_user_by_email(email)
if user is None:
return jsonify(error="Invalid credentials"), 401
digest = hashlib.sha256(password.encode()).hexdigest()
if digest != user.password_hash:
return jsonify(error="Invalid credentials"), 401
return jsonify(ok=True)