Carolus Bramnatyo Seno Mahesworo f9fc7ba011 feat: fixing bug at login page
2025-11-24 13:00:13 +07:00

65 lines
2.3 KiB
PHP

<?php
session_start();
include "config/db.php";
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username)||empty($password)){
echo "semua data harus terisi";
}else{
$sql = "SELECT * FROM users WHERE username =?";
$stmt = $db -> prepare($sql);
$stmt->bind_param('s',$username);
$stmt->execute();
$result = $stmt ->get_result();
if($result->num_rows ===1){
$user = $result ->fetch_assoc();
if(password_verify($password,$user['password'])){
$_SESSION['loggedin']='true';
$_SESSION['username']=$user['username'];
$_SESSION['id']=$user['id'];
header("location:leaderboard.php");
exit();
}else{
echo "password salah";
}
}else{
echo "username salah";
}
$stmt->close();
}
}
$db->close();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>login</title>
<link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
<link rel="stylesheet" href="/css/global.css">
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div class="container-login">
<h1 data-aos="zoom-out" data-aos-duration="1000">codebeater</h1>
<form class="login-form" action ="index.php" method="POST">
<h2 data-aos="fade-up" data-aos-duration="1000">Login to your account</h2>
<input type="text" name="username" id="username" placeholder="input your username" data-aos="fade-up" data-aos-duration="2000"><br>
<input type="password" name="password" id="password" placeholder="input your password" data-aos="fade-up" data-aos-duration="2000"><br>
<button type="submit" name="login" placeholder="input your password" data-aos="fade-up" data-aos-duration="3000">LOGIN</button>
<p placeholder="input your password" data-aos="fade-up" data-aos-duration="3000"><a href="register.php">don't have account yet?<span> register now!</span></a></p>
</form>
</div>
<script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
<script>
AOS.init();
</script>
</body>
</html>