memperbaiki login

This commit is contained in:
aldo 2025-12-01 15:07:52 +07:00
parent f3ac99887d
commit cb96761ae8

View File

@ -7,7 +7,7 @@ include 'db.php';
session_start(); session_start();
$err = ''; $err = '';
$username_input = ''; // Untuk menyimpan username agar tidak hilang jika salah password $username_input = '';
if (isset($_POST['login'])) { if (isset($_POST['login'])) {
$username_input = trim($_POST['username'] ?? ''); $username_input = trim($_POST['username'] ?? '');
@ -27,8 +27,6 @@ if (isset($_POST['login'])) {
// password_verify akan mencocokkan input user dengan HASH di database // password_verify akan mencocokkan input user dengan HASH di database
if ($user_data && password_verify($pass, $user_data['password'])) { if ($user_data && password_verify($pass, $user_data['password'])) {
// Login Berhasil!
// Regenerasi ID Session // Regenerasi ID Session
session_regenerate_id(true); session_regenerate_id(true);
@ -55,6 +53,7 @@ if (isset($_POST['login'])) {
<head> <head>
<title>Login</title> <title>Login</title>
<style> <style>
/* Style disamakan persis dengan register.php Anda */
body { font-family: Arial; background:#eef2f7; display:flex; height:100vh; justify-content:center; align-items:center; margin:0; } body { font-family: Arial; background:#eef2f7; display:flex; height:100vh; justify-content:center; align-items:center; margin:0; }
.card { width:350px; background:white; padding:20px; border-radius:10px; box-shadow:0 6px 20px rgba(0,0,0,0.1); } .card { width:350px; background:white; padding:20px; border-radius:10px; box-shadow:0 6px 20px rgba(0,0,0,0.1); }
.input { width:100%; padding:10px; margin:8px 0; border:1px solid #ccc; border-radius:8px; box-sizing: border-box; } .input { width:100%; padding:10px; margin:8px 0; border:1px solid #ccc; border-radius:8px; box-sizing: border-box; }
@ -68,7 +67,7 @@ a { text-decoration: none; color: #007bff; }
<body> <body>
<div class="card"> <div class="card">
<h2>Login</h2> <h2 style="text-align: center">Login</h2>
<?php if ($err): ?> <?php if ($err): ?>
<div class="err"><?= htmlspecialchars($err) ?></div> <div class="err"><?= htmlspecialchars($err) ?></div>