75062dbf5e
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
40 lines
1.5 KiB
Python
40 lines
1.5 KiB
Python
from flask import Blueprint, request, jsonify
|
|
import hashlib
|
|
import bcrypt
|
|
from util.logger import logger
|
|
from auth.token import verify_token
|
|
|
|
hashverifier_blueprint = Blueprint('hashverifier_tool', __name__)
|
|
|
|
|
|
@hashverifier_blueprint.route('/api/hash/verify', methods=['POST'])
|
|
def verify_hash():
|
|
user = verify_token()
|
|
if not user:
|
|
return jsonify({"message": "Nicht autorisiert"}), 401
|
|
try:
|
|
data = request.get_json() or {}
|
|
text = data.get("text", "")
|
|
hash_val = data.get("hash", "").strip()
|
|
algorithm = data.get("algorithm", "sha256")
|
|
|
|
if algorithm == "md5":
|
|
computed = hashlib.md5(text.encode()).hexdigest()
|
|
match = computed.lower() == hash_val.lower()
|
|
elif algorithm == "sha256":
|
|
computed = hashlib.sha256(text.encode()).hexdigest()
|
|
match = computed.lower() == hash_val.lower()
|
|
elif algorithm == "bcrypt":
|
|
try:
|
|
match = bcrypt.checkpw(text.encode(), hash_val.encode())
|
|
except Exception:
|
|
return jsonify({"message": "Ungültiger bcrypt-Hash"}), 400
|
|
else:
|
|
return jsonify({"message": "Unbekannter Algorithmus"}), 400
|
|
|
|
logger.info(f"Hash verify ({algorithm}) von {user['username']}: {match}")
|
|
return jsonify({"match": match})
|
|
except Exception as e:
|
|
logger.error(f"Fehler bei Hash-Verifikation: {e}")
|
|
return jsonify({"message": "Fehler bei der Verifikation"}), 500
|