Files
better_guestbook/api/setup/save.php
T
2026-10-05 10:52:31 +02:00

41 lines
922 B
PHP
Executable File

<?php
// Load Main Libary
require "../api.php";
$api = new gbAPI(false);
// Check Request body
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
$api->answer(400, [
"error" => "false_request_method",
"error_text" => "Only POST allowed"
]);
}
if (!isset($_POST["username"]) || !isset($_POST["password"]) || !isset($_POST["password_repeat"])) {
$api->answer(400, [
"error" => "missing_fields",
"error_text" => "Some fields are missing"
]);
}
$username = $_POST["username"];
$password = $_POST["password"];
$password_repeat = $_POST["password_repeat"];
// Check Passwords
if ($password !== $password_repeat) {
$api->answer(400, [
"error" => "passwords_dont_match",
"error_text" => "The passwords does not match."
]);
}
// Hash Password
$hash = password_hash($password);
// CREATE DATABASE STRUCTURE
file_get_contents(APP_PATH . "db_structure.sql");