Compare commits
2 Commits
22964ee535
...
949293fd94
| Author | SHA1 | Date | |
|---|---|---|---|
| 949293fd94 | |||
| f7382b1607 |
@ -2,11 +2,11 @@
|
||||
$host = "localhost";
|
||||
$user = "root";
|
||||
$password = "";
|
||||
$database = "users_db";
|
||||
$database = "users_db";
|
||||
|
||||
$conn = mysqli_connect($host, $user, $password, $database);
|
||||
|
||||
if ($conn->connect_error) {
|
||||
if (!$conn) {
|
||||
die("Koneksi gagal: " . mysqli_connect_error());
|
||||
}
|
||||
?>
|
||||
|
||||
15
auth.php
15
auth.php
@ -10,32 +10,31 @@ if (isset($_POST['btn-register'])) {
|
||||
$username = $_POST['username'];
|
||||
$email = $_POST['email'];
|
||||
$password = $_POST['password'];
|
||||
// Pastikan di HTML name-nya sudah 'confirm_password'
|
||||
$confirm = $_POST['confirm_password'];
|
||||
|
||||
// --- 1. VALIDASI DATA ---
|
||||
|
||||
// Cek Kosong
|
||||
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;
|
||||
}
|
||||
|
||||
// Cek Format Email (Biar gak ngawur)
|
||||
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;
|
||||
}
|
||||
|
||||
// Cek Panjang Password (Minimal 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;
|
||||
}
|
||||
|
||||
// Cek Kesamaan Password
|
||||
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;
|
||||
}
|
||||
|
||||
@ -46,7 +45,7 @@ if (isset($_POST['btn-register'])) {
|
||||
mysqli_stmt_store_result($stmt);
|
||||
|
||||
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;
|
||||
}
|
||||
mysqli_stmt_close($stmt);
|
||||
@ -57,7 +56,7 @@ if (isset($_POST['btn-register'])) {
|
||||
mysqli_stmt_bind_param($stmtInsert, "sss", $username, $email, $hashed_password);
|
||||
|
||||
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 {
|
||||
echo "Error: " . mysqli_error($conn);
|
||||
}
|
||||
@ -83,7 +82,7 @@ else if (isset($_POST['btn-login'])) {
|
||||
// JIKA GAGAL
|
||||
if (!$row || !password_verify($password, $row['password'])) {
|
||||
// Kirim sinyal error ke HTML (Kotak Merah)
|
||||
header("Location: index.html?error=gagal");
|
||||
header("Location: index.php?error=gagal");
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<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>
|
||||
<body>
|
||||
|
||||
@ -66,7 +66,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="assets index/script.js"></script>
|
||||
<script src="assets/script.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
session_start();
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: login.php");
|
||||
header("Location: index.php");
|
||||
exit();
|
||||
}
|
||||
$user = $_SESSION['user']; // username, role, id
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user