diff --git a/index.html b/index.html index 3e08308..5a9fa3a 100644 --- a/index.html +++ b/index.html @@ -1,274 +1,220 @@
- - -
@@ -281,121 +227,160 @@ input:focus {
- Login untuk bermain Memory Flip Card Game
-- Belum punya akun? - Daftar Sekarang -
+diff --git a/login.php b/login.php index e28251e..8e7f6bc 100644 --- a/login.php +++ b/login.php @@ -2,15 +2,11 @@ session_start(); require_once "Config.php"; -if (!isset($_POST['username']) || !isset($_POST['password'])) { - echo "Username atau password salah"; - exit; -} +if(isset($_POST['btn-login'])){ + $username = $_POST['username']; + $password = $_POST['password']; -$username = $_POST['username']; -$password = $_POST['password']; - -// Ambil user berdasarkan username + // Ambil user berdasarkan username $stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=?"); mysqli_stmt_bind_param($stmt, "s", $username); mysqli_stmt_execute($stmt); @@ -28,4 +24,7 @@ if (!$row || !password_verify($password, $row['password'])) { $_SESSION['username'] = $row['username']; echo ""; exit; +} + + ?> diff --git a/register.html b/register.html index eef7c7d..335a183 100644 --- a/register.html +++ b/register.html @@ -149,7 +149,7 @@ input:focus { } /* Button */ -.btn { +.btn-register { width: 100%; background: linear-gradient(45deg, purple, hotpink); color: white; @@ -245,7 +245,7 @@ input:focus {
- +diff --git a/register.php b/register.php index c315435..5f0a76e 100644 --- a/register.php +++ b/register.php @@ -2,11 +2,11 @@ session_start(); require_once "Config.php"; -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - $username = trim($_POST['username']); - $email = trim($_POST['email']); - $password = trim($_POST['password']); - $confirmPassword = trim($_POST['confirm_password']); +if(isset($_POST['btn-register'])) { + $username = $_POST['username']; + $email = $_POST['email']; + $password = $_POST['password']; + $confirmPassword = password_hash($_POST['confirm_password'],PASSWORD_DEFAULT); if (!$username || !$email || !$password || !$confirmPassword) { echo ""; @@ -28,7 +28,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } - // cek username & email di database + $stmt = mysqli_prepare($conn, "SELECT id FROM user WHERE username=? OR email=?"); mysqli_stmt_bind_param($stmt, "ss", $username, $email); mysqli_stmt_execute($stmt); @@ -39,10 +39,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { exit; } - // hash password - $hash = password_hash($password, PASSWORD_DEFAULT); - - // insert user $stmt = mysqli_prepare($conn, "INSERT INTO user (username, email, password, role) VALUES (?, ?, ?, 'player')"); mysqli_stmt_bind_param($stmt, "sss", $username, $email, $hash); mysqli_stmt_execute($stmt);