<?php

include "connection.php";
include "../admin/config/functions/func_misc.php";


    if (isset($_SERVER['HTTP_ACTION'])) {
        if ($_SERVER['REQUEST_METHOD'] == 'POST') {
            $action = $_SERVER['HTTP_ACTION'];
            if ($action == "SECURITY") {
                $keyCode = $_REQUEST['keyCode'];
                $kiv = randomString();
                $ksp = randomString();
                $vkiv = randomString();
                $vksp = randomString();

                $kivHash = passwordHash($kiv . $keyCode, $mySalt);
                $kspHash = passwordHash($ksp . $keyCode, $mySalt);

                $q = mysqli_query($dbc, "INSERT INTO keycodeauth_tbl (id,kiv, ksp,dkiv,dksp) VALUES (UUID(),'$kivHash','$kspHash','$vkiv','$vksp')");
                if ($q) {
                    //echo "(" . $kiv . "/" . $ksp . "*" . $vkiv . "!" . $vksp . ")";
                    echo "({$kiv}/{$ksp}*{$vkiv}!{$vksp})";
                }

            } else {
                echo "Error2";
            }
        } else {
            echo "Error1";
        }
    } else {
        echo "Error";
    }



function randomString($length = 32) {
    $str = "";
    $characters = array_merge(range('A','Z'), range('a','z'), range('0','9'));
    $max = count($characters) - 1;
    for ($i = 0; $i < $length; $i++) {
        $rand = mt_rand(0, $max);
        $str .= $characters[$rand];
    }
    return $str;
}