7f9c5c874a
- backend/tools/hasher.py: POST /api/hash/sha256 and /api/hash/bcrypt (bcrypt added to requirements) - backend/tools/base64tool.py: POST /api/base64/encode and /api/base64/decode - backend/tools/jwtdecoder.py: POST /api/jwt/decode (signature verification disabled) - backend/tools/passwordgen.py: POST /api/password/generate with charset and length options - backend/tools/timestamp.py: POST /api/timestamp/convert (unix<->date, ISO 8601 + German format) - backend/tools/textdiff.py: POST /api/text/diff returning structured added/removed/unchanged lines - All blueprints registered in app.py and tools/__init__.py - React components with copy button, dark/light mode support via CSS variables - ToolOverview rebuilt as card grid; App.jsx routes added for all tools Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from flask import Blueprint, request, jsonify
|
|
import secrets
|
|
import string
|
|
from util.logger import logger
|
|
from auth.token import verify_token
|
|
|
|
passwordgen_blueprint = Blueprint('passwordgen_tool', __name__)
|
|
|
|
|
|
@passwordgen_blueprint.route('/api/password/generate', methods=['POST'])
|
|
def generate_password():
|
|
user = verify_token()
|
|
if not user:
|
|
return jsonify({"message": "Nicht autorisiert"}), 401
|
|
try:
|
|
data = request.get_json()
|
|
length = min(max(int(data.get("length", 16)), 8), 64)
|
|
use_uppercase = data.get("uppercase", True)
|
|
use_lowercase = data.get("lowercase", True)
|
|
use_numbers = data.get("numbers", True)
|
|
use_symbols = data.get("symbols", False)
|
|
|
|
charset = ""
|
|
if use_uppercase:
|
|
charset += string.ascii_uppercase
|
|
if use_lowercase:
|
|
charset += string.ascii_lowercase
|
|
if use_numbers:
|
|
charset += string.digits
|
|
if use_symbols:
|
|
charset += string.punctuation
|
|
|
|
if not charset:
|
|
return jsonify({"message": "Mindestens ein Zeichensatz muss ausgewählt sein"}), 400
|
|
|
|
password = ''.join(secrets.choice(charset) for _ in range(length))
|
|
logger.info(f"Passwort generiert von {user['username']}")
|
|
return jsonify({"password": password})
|
|
except Exception as e:
|
|
logger.error(f"Fehler Passwortgenerator: {e}")
|
|
return jsonify({"message": "Fehler beim Generieren"}), 500
|