create login.php

This commit is contained in:
jakani24
2024-01-14 15:27:50 +01:00
parent 8c9048d4e5
commit 51818ca5fc
3 changed files with 55 additions and 3 deletions

View File

@@ -78,9 +78,9 @@
$email=htmlspecialchars($_POST["email"]);
$username=htmlspecialchars($_POST["username"]);
$password=htmlspecialchars($_POST["password"]);
$password=$_POST["password"];
$permissions="1111111111";
$hash=password_hash('user_password_here', PASSWORD_BCRYPT);
$hash=password_hash($password, PASSWORD_BCRYPT);
$stmt->execute();
$stmt->close();

View File

@@ -4,6 +4,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<title>Cyberhex login page</title>
</head>
<body>
@@ -12,7 +13,7 @@
<div class="col-md-6">
<div class="card">
<div class="card-header">
<h4>Login</h4>
<h4>Login to Cyberhex</h4>
</div>
<div class="card-body">
<form>
@@ -31,6 +32,56 @@
</div>
</div>
</div>
<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
//include db pw
include "../../../config.php"
// Retrieve user input
$username = htmlspecialchars($_POST["username"]);
$password = $_POST["password"];
// Create a connection
$conn = new mysqli($DB_SERVERNAME, $DB_USERNAME, $DB_PASSWORD, $DB_DATABASE);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM users WHERE username = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("s", $username);
// Execute the statement
$stmt->execute();
// Get the result
$result = $stmt->get_result();
// Check if the user exists and verify the password
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
if (password_verify($password, $row['password'])) {
echo '<div class="alert alert-success" role="alert">
Login successful!
</div>';
} else {
echo '<div class="alert alert-danger" role="alert">
Incorrect username or password.
</div>';
}
} else {
echo '<div class="alert alert-danger" role="alert">
Incorrect username or password.
</div>';
}
// Close the connection
$stmt->close();
$conn->close();
}
?>
</body>
</html>

View File

@@ -24,6 +24,7 @@ if(isset($_GET["page"])){
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<title>Cyberhex</title>
</head>
<body>
<!-- navbar -->