In what scenarios would implementing a custom login system be more beneficial than relying on htaccess authentication for accessing a SQL-based reporting tool connected to Active Directory?
Implementing a custom login system may be more beneficial than relying on htaccess authentication for accessing a SQL-based reporting tool connected to Active Directory if you need more control over user permissions, additional features such as password reset or account management, or if you want to integrate the login system with other parts of your application.
<?php
session_start();
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$username = $_POST['username'];
$password = $_POST['password'];
// Validate username and password against Active Directory or any other authentication method
// If authentication is successful, set session variables and redirect to the reporting tool
// Example:
if ($username === 'admin' && $password === 'password') {
$_SESSION['username'] = $username;
header('Location: reporting_tool.php');
exit;
} else {
$error = 'Invalid username or password';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<?php if (isset($error)) { echo "<p>$error</p>"; } ?>
<form method="post" action="">
<label for="username">Username:</label>
<input type="text" name="username" id="username" required><br>
<label for="password">Password:</label>
<input type="password" name="password" id="password" required><br>
<input type="submit" value="Login">
</form>
</body>
</html>