v0.0.1 Added the first files and made a login system.

This commit is contained in:
Victor
2021-06-01 11:29:56 +02:00
parent 78df7dd754
commit dfb9103157
20 changed files with 223 additions and 26 deletions
+41
View File
@@ -0,0 +1,41 @@
<?php
require_once "../../bootstrap.php";
use Illuminate\Support\Str;
session_start();
if (isset($_POST['loginsubmit'])) {
$username = $_POST["username"];
$password = $_POST["password"];
$user = User::query()->firstWhere('name', $username);
if ($user) {
$hashedPassword = $user->password;
if (password_verify($password, $hashedPassword)) {
$token = Str::random(100);
$password = User::firstWhere('id', '=', $user->id);
$password->remember_token = $token;
if ($password->save()) {
$_SESSION['token'] = $token;
$_SESSION['name'] = $username;
header('location: ../../Frontend/home.php?login=success');
exit();
http_response_code(200);
} else {
session_destroy();
http_response_code(500);
}
} else {
session_destroy();
http_response_code(401);
echo json_encode(["message" => "Wrong password"]);
}
} else {
session_destroy();
http_response_code(401);
echo json_encode(["message" => "User was not found"]);
}
} else {
http_response_code(400);
}