diff --git a/login.html b/login.html index c89dbe5..8d2848f 100644 --- a/login.html +++ b/login.html @@ -313,102 +313,102 @@ input:focus {

+ \ No newline at end of file diff --git a/login.php b/login.php index ae1ea99..3948f54 100644 --- a/login.php +++ b/login.php @@ -5,22 +5,17 @@ include "koneksi.php"; $username = $_POST['username']; $password = $_POST['password']; -$enc = md5($password); - -$stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=? AND password=?"); -mysqli_stmt_bind_param($stmt, "ss", $username, $enc); +$stmt = mysqli_prepare($conn, "SELECT * FROM user WHERE username=?"); +mysqli_stmt_bind_param($stmt, "s", $username); mysqli_stmt_execute($stmt); - $result = mysqli_stmt_get_result($stmt); -if ($row = mysqli_fetch_assoc($result)) { +if ($row && password_verify($password, $row['password'])) { $_SESSION['username'] = $row['username']; - $_SESSION['email'] = $row['email']; - - header("Location: mainboard.html"); + echo "OK"; exit; - } else { - echo ""; + echo "Username atau password salah"; + exit; } ?> diff --git a/register.html b/register.html index 1abb2b2..eef7c7d 100644 --- a/register.html +++ b/register.html @@ -255,18 +255,19 @@ input:focus { + diff --git a/register.php b/register.php index 9a5858c..6507bb1 100644 --- a/register.php +++ b/register.php @@ -1,34 +1,53 @@ alert('Format email tidak valid!'); window.history.back();"; + if (!$username || !$email || !$password || !$confirmPassword) { + echo ""; + exit; + } + + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + echo ""; + exit; + } + + if ($password !== $confirmPassword) { + echo ""; + exit; + } + + if (strlen($password) < 6) { + echo ""; + 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); + mysqli_stmt_store_result($stmt); + + if (mysqli_stmt_num_rows($stmt) > 0) { + echo ""; + 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); + + echo ""; exit; } - -if ($password != $confirm) { - echo ""; - exit; -} - -$cek = mysqli_query($conn, "SELECT * FROM user WHERE username='$username' OR email='$email'"); -if (mysqli_num_rows($cek) > 0) { - echo ""; - exit; -} - -$hash = md5($password); - -$sql = "INSERT INTO user (username, email, password) VALUES ('$username', '$email', '$hash')"; -if (mysqli_query($conn, $sql)) { - echo ""; -} else { - echo "Error: " . mysqli_error($conn); -} - ?>