<?php
require_once('xconn.php');
 
 session_start();
    if ($conn ->connect_error) {
    die("Connection failed: " . $conn ->connect_error);
    }
 
    $username = htmlspecialchars($_POST['username']);
    $password = htmlspecialchars($_POST['password']);


    $result = mysqli_query($conn,"SELECT d_usuario, d_password, c_cliente FROM t_usuarios WHERE d_usuario='" . $username . "'");

    if($row = mysqli_fetch_array($result)){
        if (password_verify($password, $row['d_password'])) {
            $_SESSION['c_usuario'] = $row['c_cliente'];
            $_SESSION['d_usuario'] = $username;
            header("Location: dashboard.php");
        } else {
            header("Location: index.php");
            exit();
        }
    }else{
            header("Location: index.php");
            exit();
    }

session_detroy();
?>