Implement user authentication and registration; enhance error handling and database interaction in API

This commit is contained in:
marc-go committed 2026-10-04 19:21:38 +02:00
1 parent 2ac799d0a4
commit c50c1bd122
6 files changed
+163 -16

No files matched your search

+36 -1
View File
@@ -2,4 +2,39 @@
// Load Main Libary
require "../api.php";
bin2hex(random_bytes(32))
$api = new gbAPI(true);
// 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 = hash("sha256", $password);
// CREATE DATABASE STRUCTURE
file_get_contents(APP_PATH . "db_structure.sql");