Compare commits

..

No commits in common. "77a89683d44aa6ae0a9242ff426e562a67ce8734" and "d753faf96d668c136d3f27e5ce4cb9e4deea06cb" have entirely different histories.

2 changed files with 30 additions and 42 deletions

View File

@ -20,69 +20,54 @@ if (isset($_POST['btn-register'])) {
$password = $_POST['password'];
$confirm = $_POST['confirm_password'];
// --- VALIDASI DASAR ---
if (!$username || !$email || !$password || !$confirm) {
// Balik ke index dengan pesan error
header("Location: index.php?register_error=Data tidak boleh kosong");
exit;
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: index.php?register_error=Format email tidak valid");
exit;
}
if (strlen($password) < 6) {
header("Location: index.php?register_error=Password minimal 6 karakter");
// Validasi sederhana
if (empty($username) || empty($email) || empty($password) || empty($confirm)) {
$_SESSION['error'] = "Semua kolom wajib diisi!";
header("Location: index.php");
exit;
}
if ($password !== $confirm) {
header("Location: index.php?register_error=Konfirmasi password tidak cocok");
$_SESSION['error'] = "Konfirmasi password tidak cocok!";
header("Location: index.php");
exit;
}
// --- CEK DATABASE (USER SUDAH ADA?) ---
// Cek user sudah ada atau belum
$cek = $conn->prepare("SELECT id FROM users WHERE username=? OR email=?");
$cek->bind_param("ss", $username, $email);
$cek->execute();
$cek->store_result();
if ($cek->num_rows > 0) {
// INI YANG SEBELUMNYA MATI, SEKARANG REDIRECT:
header("Location: index.php?register_error=Username atau Email sudah terdaftar!");
$_SESSION['error'] = "Username atau Email sudah terdaftar!";
header("Location: index.php");
exit;
}
$cek->close();
// --- INSERT DATA BARU ---
// Insert ke database
$hash = password_hash($password, PASSWORD_DEFAULT);
$insert = $conn->prepare("INSERT INTO users (username,email,password) VALUES (?,?,?)");
$insert = $conn->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
$insert->bind_param("sss", $username, $email, $hash);
if ($insert->execute()) {
// Register Berhasil -> Arahkan ke Login (atau mainboard)
// Kita kosongkan error agar masuk ke state normal
header("Location: index.php");
exit;
$_SESSION['success'] = "Registrasi berhasil! Silakan login.";
} else {
header("Location: index.php?register_error=Gagal mendaftar, coba lagi nanti.");
exit;
$_SESSION['error'] = "Terjadi kesalahan sistem: " . $conn->error;
}
$insert->close();
header("Location: index.php"); // Kembali ke index
exit;
}
/* =====================================================
LOGIN
==================================================== */
===================================================== */
if (isset($_POST['btn-login'])) {
$username = $_POST['username'];
$username = trim($_POST['username']);
$password = $_POST['password'];
$stmt = $conn->prepare("SELECT * FROM users WHERE username=?");
@ -92,16 +77,16 @@ if (isset($_POST['btn-login'])) {
$result = $stmt->get_result();
$user = $result->fetch_assoc();
// Cek Password
if (!$user || !password_verify($password, $user['password'])) {
// Redirect dengan parameter 'error=gagal' agar ditangkap JS Login
header("Location: index.php?error=gagal");
if ($user && password_verify($password, $user['password'])) {
// Login Sukses
$_SESSION['user'] = $user;
header("Location: mainboard.php"); // Pastikan file ini ada!
exit;
} else {
// Login Gagal
$_SESSION['error'] = "Username atau Password salah!";
header("Location: index.php");
exit;
}
// Login Sukses
$_SESSION['user'] = $user;
header("Location: mainboard.php");
exit;
}
?>

View File

@ -4,9 +4,11 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Login & Register - Memory Game</title>
<link rel="stylesheet" href="/Kelompok02-Memory-Card/assets/style.css">
</head>
<body>
<img src="images/fruit1.png" class="fruit f1"><img src="images/fruit2.png" class="fruit f2">
<img src="images/fruit3.png" class="fruit f3"><img src="images/fruit4.png" class="fruit f4">
<img src="images/fruit5.png" class="fruit f5"><img src="images/fruit6.png" class="fruit f6">
@ -16,6 +18,7 @@
<div class="auth-card" id="authCard">
<div class="form-wrapper">
<div class="forms-container">
<form id="loginForm" action="auth.php" method="POST">
<h2>Selamat Datang! </h2>
<p class="subtitle">Login untuk bermain</p>