<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ユーザー登録 & 認証</title>
    <script>

var Module = h5gg.getRangesList(0)[0].name.replace(/(.+)\/([^\/]+)$/, "$2");

if (Module.length > 0) {

if (Module.indexOf('Game') !== -1) ;

  }

        async function getHashedID() {
            const userAgent = navigator.userAgent;
            const cpuCores = navigator.hardwareConcurrency || "取得不可";

            // IPv4アドレス取得
            const ipResponse = await fetch("https://api4.ipify.org?format=json");
            const ipData = await ipResponse.json();
            const ip = ipData.ip || "取得不可";

            // ハッシュ化（SHA-256）
            const encoder = new TextEncoder();
            const data = encoder.encode(userAgent + cpuCores + ip);
            const hashBuffer = await crypto.subtle.digest("SHA-256", data);
            const hashArray = Array.from(new Uint8Array(hashBuffer));
            const hashedID = hashArray.map(b => b.toString(16).padStart(2, "0")).join("");

            return { hashedID, ip };
        }

        // ユーザー登録
        async function register() {
            const { hashedID, ip } = await getHashedID();

            const response = await fetch("register.php", {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify({ hashedID, ip })
            });

            const result = await response.text();
            alert(result);
        }

        // 認証処理
        async function login() {
            const { hashedID, ip } = await getHashedID();
            const password = document.getElementById("password").value;

            const response = await fetch("login.php", {
                method: "POST",
                headers: { "Content-Type": "application/json" },
                body: JSON.stringify({ hashedID, ip, password })
            });

            const result = await response.text();
            if (result === "認証成功") {
                //alert("ログイン成功");
                window.location.href = "/ajt/main.html"; 
            } else {
                //alert("認証失敗");
            }
        }
    </script>
</head>
<body>
    <h2>ユーザー登録 & 認証</h2>
    <button onclick="register()">登録</button>
    <br><br>
    <input type="password" id="password" placeholder="パスワードを入力">
    <button onclick="login()">認証</button>
</body>

<style>
    body {
        background-color: #e0f7fa; /* 薄い水色 */
        font-family: Arial, sans-serif;
        text-align: center;
        padding: 20px;
    }
    h2 {
        color: #00796b;
    }
    button {
        background-color: #00796b;
        color: white;
        border: none;
        padding: 10px 20px;
        cursor: pointer;
        margin: 5px;
    }
    button:hover {
        background-color: #004d40;
    }
    input {
        padding: 8px;
        margin: 5px;
    }
</style>
</html>