125 lines
3.4 KiB
PHP
125 lines
3.4 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
|
|
if (!isset($_SESSION['login_attempts'])) {
|
|
$_SESSION['login_attempts'] = 0;
|
|
}
|
|
|
|
if ($_SESSION['login_attempts'] >= 5) {
|
|
die("Muitas tentativas de login. Por favor, tente novamente mais tarde.");
|
|
}
|
|
|
|
// Após uma tentativa de login falha, incremente:
|
|
$_SESSION['login_attempts'] += 1;
|
|
|
|
// Redirecionar para a página principal se já estiver logado
|
|
if (isset($_SESSION['user_id'])) {
|
|
header("Location: index.php");
|
|
exit();
|
|
}
|
|
|
|
$message = '';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
// Conectar ao banco de dados
|
|
$mysqli = new mysqli("10.15.0.42", "root", "34641747", "valida");
|
|
|
|
if ($mysqli->connect_error) {
|
|
die("Connection failed: " . $mysqli->connect_error);
|
|
}
|
|
|
|
$username = $mysqli->real_escape_string($_POST['username']);
|
|
$password = $_POST['password'];
|
|
|
|
// Buscar o usuário no banco de dados
|
|
$stmt = $mysqli->prepare("SELECT id, password FROM users WHERE username = ?");
|
|
$stmt->bind_param("s", $username);
|
|
$stmt->execute();
|
|
$stmt->store_result();
|
|
|
|
if ($stmt->num_rows == 1) {
|
|
$stmt->bind_result($user_id, $hashed_password);
|
|
$stmt->fetch();
|
|
|
|
if (password_verify($password, $hashed_password)) {
|
|
// Senha correta; iniciar a sessão
|
|
$_SESSION['user_id'] = $user_id;
|
|
$_SESSION['username'] = $username;
|
|
header("Location: index.php");
|
|
exit();
|
|
} else {
|
|
$message = "Senha incorreta.";
|
|
}
|
|
} else {
|
|
$message = "Usuário não encontrado.";
|
|
}
|
|
|
|
$stmt->close();
|
|
$mysqli->close();
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="pt-BR">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Login - Sistema de Ferramentas</title>
|
|
<link rel="stylesheet" href="style.css">
|
|
<style>
|
|
/* Estilos básicos para o formulário de login */
|
|
.login-container {
|
|
max-width: 400px;
|
|
margin: 100px auto;
|
|
padding: 20px;
|
|
background-color: white;
|
|
border-radius: 5px;
|
|
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
|
}
|
|
.login-container h2 {
|
|
text-align: center;
|
|
}
|
|
.login-container .form-group {
|
|
margin-bottom: 15px;
|
|
}
|
|
.login-container .form-group label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
}
|
|
.login-container .form-group input {
|
|
width: 100%;
|
|
padding: 8px;
|
|
box-sizing: border-box;
|
|
}
|
|
.login-container .error {
|
|
color: red;
|
|
text-align: center;
|
|
margin-bottom: 15px;
|
|
}
|
|
.login-container button {
|
|
width: 100%;
|
|
padding: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="login-container">
|
|
<h2>Login</h2>
|
|
<?php if ($message): ?>
|
|
<p class="error"><?php echo htmlspecialchars($message); ?></p>
|
|
<?php endif; ?>
|
|
<form action="login.php" method="post">
|
|
<div class="form-group">
|
|
<label for="username">Usuário:</label>
|
|
<input type="text" id="username" name="username" required autofocus>
|
|
</div>
|
|
<div class="form-group">
|
|
<label for="password">Senha:</label>
|
|
<input type="password" id="password" name="password" required>
|
|
</div>
|
|
<button type="submit">Entrar</button>
|
|
</form>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
|