Merge branch 'main' of https://git-eng.ukwms.ac.id/2526-web/Kelompok02-Memory-Card
This commit is contained in:
commit
f7382b1607
@ -1,12 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
$host = "localhost";
|
$host = "localhost";
|
||||||
$user = "root";
|
$user = "root";
|
||||||
$password = "";
|
$password = "";
|
||||||
$database = "users_db";
|
$database = "users_db";
|
||||||
|
|
||||||
$conn = mysqli_connect($host, $user, $password, $database);
|
$conn = mysqli_connect($host, $user, $password, $database);
|
||||||
|
|
||||||
if ($conn->connect_error) {
|
if (!$conn) {
|
||||||
die("Koneksi gagal: " . mysqli_connect_error());
|
die("Koneksi gagal: " . mysqli_connect_error());
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
15
auth.php
15
auth.php
@ -10,32 +10,31 @@ if (isset($_POST['btn-register'])) {
|
|||||||
$username = $_POST['username'];
|
$username = $_POST['username'];
|
||||||
$email = $_POST['email'];
|
$email = $_POST['email'];
|
||||||
$password = $_POST['password'];
|
$password = $_POST['password'];
|
||||||
// Pastikan di HTML name-nya sudah 'confirm_password'
|
|
||||||
$confirm = $_POST['confirm_password'];
|
$confirm = $_POST['confirm_password'];
|
||||||
|
|
||||||
// --- 1. VALIDASI DATA ---
|
// --- 1. VALIDASI DATA ---
|
||||||
|
|
||||||
// Cek Kosong
|
// Cek Kosong
|
||||||
if (empty($username) || empty($email) || empty($password) || empty($confirm)) {
|
if (empty($username) || empty($email) || empty($password) || empty($confirm)) {
|
||||||
echo "<script>alert('Semua data wajib diisi!'); window.location='index.html';</script>";
|
echo "<script>alert('Semua data wajib diisi!'); window.location='index.php';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cek Format Email (Biar gak ngawur)
|
// Cek Format Email (Biar gak ngawur)
|
||||||
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||||
echo "<script>alert('Format email tidak valid! (contoh: nama@email.com)'); window.location='index.html';</script>";
|
echo "<script>alert('Format email tidak valid! (contoh: nama@email.com)'); window.location='index.php';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cek Panjang Password (Minimal 6)
|
// Cek Panjang Password (Minimal 6)
|
||||||
if (strlen($password) < 6) {
|
if (strlen($password) < 6) {
|
||||||
echo "<script>alert('Password terlalu pendek! Minimal 6 karakter.'); window.location='index.html';</script>";
|
echo "<script>alert('Password terlalu pendek! Minimal 6 karakter.'); window.location='index.php';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cek Kesamaan Password
|
// Cek Kesamaan Password
|
||||||
if ($password !== $confirm) {
|
if ($password !== $confirm) {
|
||||||
echo "<script>alert('Password dan Konfirmasi tidak cocok!'); window.location='index.html';</script>";
|
echo "<script>alert('Password dan Konfirmasi tidak cocok!'); window.location='index.php';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ if (isset($_POST['btn-register'])) {
|
|||||||
mysqli_stmt_store_result($stmt);
|
mysqli_stmt_store_result($stmt);
|
||||||
|
|
||||||
if (mysqli_stmt_num_rows($stmt) > 0) {
|
if (mysqli_stmt_num_rows($stmt) > 0) {
|
||||||
echo "<script>alert('Username atau Email sudah terpakai! Ganti yang lain.'); window.location='index.html';</script>";
|
echo "<script>alert('Username atau Email sudah terpakai! Ganti yang lain.'); window.location='index.php';</script>";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
mysqli_stmt_close($stmt);
|
mysqli_stmt_close($stmt);
|
||||||
@ -57,7 +56,7 @@ if (isset($_POST['btn-register'])) {
|
|||||||
mysqli_stmt_bind_param($stmtInsert, "sss", $username, $email, $hashed_password);
|
mysqli_stmt_bind_param($stmtInsert, "sss", $username, $email, $hashed_password);
|
||||||
|
|
||||||
if (mysqli_stmt_execute($stmtInsert)) {
|
if (mysqli_stmt_execute($stmtInsert)) {
|
||||||
echo "<script>alert('Registrasi Berhasil! Silakan Login.'); window.location='index.html';</script>";
|
echo "<script>alert('Registrasi Berhasil! Silakan Login.'); window.location='index.php';</script>";
|
||||||
} else {
|
} else {
|
||||||
echo "Error: " . mysqli_error($conn);
|
echo "Error: " . mysqli_error($conn);
|
||||||
}
|
}
|
||||||
@ -83,7 +82,7 @@ else if (isset($_POST['btn-login'])) {
|
|||||||
// JIKA GAGAL
|
// JIKA GAGAL
|
||||||
if (!$row || !password_verify($password, $row['password'])) {
|
if (!$row || !password_verify($password, $row['password'])) {
|
||||||
// Kirim sinyal error ke HTML (Kotak Merah)
|
// Kirim sinyal error ke HTML (Kotak Merah)
|
||||||
header("Location: index.html?error=gagal");
|
header("Location: index.php?error=gagal");
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Login & Register - Memory Game</title>
|
<title>Login & Register - Memory Game</title>
|
||||||
|
|
||||||
<link rel="stylesheet" href="assets index/style.css">
|
<link rel="stylesheet" href="/Kelompok02-Memory-Card/assets/style.css">
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@ -66,7 +66,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script src="assets index/script.js"></script>
|
<script src="assets/script.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
if (!isset($_SESSION['user'])) {
|
if (!isset($_SESSION['user'])) {
|
||||||
header("Location: login.php");
|
header("Location: index.php");
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
$user = $_SESSION['user']; // username, role, id
|
$user = $_SESSION['user']; // username, role, id
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user