<?php

echo'<h2>Login no sistema do Gabriel</h2>';

session_start();
require 'conectabanco.php';

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $usuario = $_POST["usuario"];
    $senha = $_POST["senha"];

   // $pdo = conectarBanco();
    $pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);    
    $stmt = $pdo->prepare("SELECT * FROM usuarios WHERE usuario = :usuario");
    $stmt->bindParam(":usuario", $usuario);
    $stmt->execute();
    $user = $stmt->fetch(PDO::FETCH_ASSOC);

    if ($user && password_verify($senha, $user["senha"])) {
        $_SESSION["usuario"] = $usuario;
        header("Location: dashboard.php");
        exit;
    } else {
        echo "Usuário ou senha inválidos!";
    }
}
?>

<form method="post" action="">
    <table>
    <tr>
        <td><label><strong>Usuário:</strong></label></td>
        <td><input type="text" name="usuario" required></td>
        
        <td><label><strong>Senha:</strong></label></td>
        <td><input type="password" name="senha" required></td>
        <td><button style='background-color: green; font-family: verdana; color: white;' type="submit" >Login</button></td>
    </table>
</form>
