106 lines
2.6 KiB
PHP
106 lines
2.6 KiB
PHP
<?php
|
|
session_start();
|
|
$conn = new mysqli("localhost","root","","breakout_db");
|
|
if($conn->connect_error){ die("DB Error"); }
|
|
|
|
// Register
|
|
if(isset($_POST['register'])){
|
|
$u = $_POST['user'];
|
|
$p = password_hash($_POST['pass'], PASSWORD_DEFAULT);
|
|
$conn->query("INSERT INTO users(username,password,highscore) VALUES('$u','$p',0)");
|
|
}
|
|
|
|
// Login
|
|
if(isset($_POST['login'])){
|
|
$u = $_POST['user'];
|
|
$p = $_POST['pass'];
|
|
$res = $conn->query("SELECT * FROM users WHERE username='$u'");
|
|
if($row = $res->fetch_assoc()){
|
|
if(password_verify($p, $row['password'])){
|
|
$_SESSION['user'] = $u;
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Login & Register</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
|
|
<!-- Font & Icons -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
|
|
<style>
|
|
body {
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
height: 100vh;
|
|
margin: 0;
|
|
}
|
|
|
|
/* Membuat box tampak seperti popup modal */
|
|
.login-box {
|
|
position: relative;
|
|
width: 380px;
|
|
background: rgba(255, 255, 255, 0.15);
|
|
backdrop-filter: blur(12px);
|
|
border-radius: 15px;
|
|
padding: 25px;
|
|
box-shadow: 0 8px 32px rgba(255, 255, 255, 0.86);
|
|
animation: popup 0.4s ease;
|
|
}
|
|
|
|
/* Animasi muncul */
|
|
@keyframes popup {
|
|
from {
|
|
opacity: 0;
|
|
transform: scale(0.85);
|
|
}
|
|
to {
|
|
opacity: 1;
|
|
transform: scale(1);
|
|
}
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="login-box">
|
|
|
|
<h2><i class="fas fa-user"></i> Login</h2>
|
|
<form method="POST">
|
|
<input name="user" placeholder="Username" required>
|
|
<input name="pass" type="password" placeholder="Password" required>
|
|
<button name="login">Login</button>
|
|
</form>
|
|
|
|
<hr style="
|
|
margin: 25px 0;
|
|
border: 1px solid rgba(0, 0, 0, 1);
|
|
width: 90%;
|
|
">
|
|
|
|
<h2><i class="fas fa-user-plus"></i> Register</h2>
|
|
<form method="POST">
|
|
<input name="user" placeholder="Username" required>
|
|
<input name="pass" type="password" placeholder="Password" required>
|
|
<button name="register">Register</button>
|
|
</form>
|
|
|
|
<a href="index.php" class="back-button" style="margin-top:20px; display:inline-block;">
|
|
<i class="fas fa-arrow-left"></i> Back
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|
|
|