Sourcecode

Captcha/index.php


index.php

<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);

use de\themarcraft\utils\Captcha;

include('de/themarcraft/utils/Captcha.php');
include('de/themarcraft/utils/Utils.php');

$captcha = new Captcha();

if (!isset($_GET['verify'])) {

    ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Captcha Skript | tmcz.de</title>
        <meta name="description" content="Captcha Skript mit PHP">
        <link href="https://cdn.tmczs.de/bIgSJ1VGo2.css" rel="stylesheet"><!-- Bootstrap CSS -->
        <link rel="icon" href="https://cdn.tmczs.de/Logo.svg">
        <script src="https://cdn.tmczs.de/BJO2Sc0Xlo"></script>
        <script src="https://kit.fontawesome.com/a70d399742.js?v=1" crossorigin="anonymous"></script>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
    <div class="container mt-3">
        <h1>TMCZ Captcha Skript</h1>
        <hr class="mt-3">
    </div>
    <div class="container mt-3">
        <form method="post" action="?verify=1">
            <div class="mb-3">
                <label for="captchaInput" class="form-label">Löse das Captcha</label>
                <div class="input-group input-group-lg">
                    <img id="captchaImage" class="input-group-text" height="64px" style="padding: 0"
                         src="<?= $captcha->getCaptchaImage() ?>" alt="Captcha" onclick="resizeCaptcha()">
                    <input type="hidden" name="captchaSolution" value="<?= $captcha->getEncryptedCaptcha() ?>">
                    <input type="text" class="form-control" placeholder="" aria-label="" id="captchaInput"
                           name="captchaInput"
                           aria-describedby="captchaInput">
                </div>
            </div>
            <div>
                <input type="submit" class="btn btn-success" value="Überprüfen">
            </div>
        </form>
    </div>
    <script>
        function resizeCaptcha() {
            let captchaImage = document.getElementById('captchaImage');
            if (captchaImage.getAttribute('height') == '64px') {
                captchaImage.setAttribute('width', "100%");
                captchaImage.removeAttribute('height');
            } else {
                captchaImage.setAttribute('height', "64px");
                captchaImage.removeAttribute('width');
            }
        }
    </script>
    </body>
    <?php

}else{?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Captcha Skript | tmcz.de</title>
        <meta name="description" content="Captcha Skript mit PHP">
        <link href="https://cdn.tmczs.de/bIgSJ1VGo2.css" rel="stylesheet"><!-- Bootstrap CSS -->
        <link rel="icon" href="https://cdn.tmczs.de/Logo.svg">
        <script src="https://cdn.tmczs.de/BJO2Sc0Xlo"></script>
        <script src="https://kit.fontawesome.com/a70d399742.js?v=1" crossorigin="anonymous"></script>
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
    <div class="container mt-3">
        <h1>TMCZ Captcha Skript</h1>
        <hr class="mt-3">
    </div>
    <div class="container mt-3">
        <?php
        if (isset($_POST['captchaSolution']) && isset($_POST['captchaInput'])) {
            if ($captcha::verifyCaptcha($_POST['captchaSolution'], $_POST['captchaInput'])) {
                echo '<p class="mb-3 alert alert-success">';
                echo 'Das Captcha wurde richtig gelöst';
                echo '</p>';
            }else{
                echo '<p class="mb-3 alert alert-danger">';
                echo 'Das Captcha wurde nicht richtig gelöst';
                echo '</p>';
            }
        }
        ?>
        <a class="btn btn-primary" href="/">Zurück</a>
    </div>
<?php }?>

    <div class="container">
        <hr class="mt-3">
        <h3>Informationen zu diesem Programm</h3>
        <p>Dieses Programm wurde mithilfe von OOP PHP geschrieben. Es wurde die PHP Library <b>GD</b> zum erstellen der Bilder verwendet. Die Buchstaben vom Captcha wurden mithilfe von Base64 und PHP Password Hash (SHA_265) <code>password_hash()</code> verschlüsselt und werden dann vom überprüfungsscript entschlüsselt und mit <code>password_verify()</code> überprüft.</p>
    </div>
</body>
<?php include('templates/footer.html');
?>