How to allow login in the system validating user and password by the database in php?

0

Next Galley: I have an html form where I get this data and send it to an action php where the data is processed and sent to the database. This part is ok, the data goes right and everything. Now I have another login html screen. This action screen is forwarded to a php validation.php where the code is:

<?php

session_start ();

//INICIA A CONEXÃO COM O BANCO DE DADOS
$servername = "localhost";
$username = "meuUsuario";
$password = "minhaSenha";
$dbname = "meuBanco";

$conexao = new mysqli($servername, $username, $password, $dbname);

if (!$conexao) {
    die("Não foi possível conectar ao banco de dados" . mysqli_connect_error());
}

$usuario = mysqli_real_escape_string($conexao, $_POST['usuario']);
$senha = mysqli_real_escape_string($conexao, md5($_POST['senha']));

// Validação do usuário/senha digitados
$sql = "SELECT id, Nome, Senha FROM cadastroMorador WHERE Usuario = '$usuario' AND Senha = '$senha' LIMIT 1";
$query = mysqli_query($conexao, $sql);
if ($query) {
    // Mensagem de erro quando os dados são inválidos e/ou o usuário não foi encontrado
    $row_usuario = mysqli_fetch_assoc($query);
    if(password_verify($senha, row_usuario['Senha'])){
       header("Location: index.html");

    } else {
    echo "Login inválido!";
    header("Location: signin.html"); 
    }


} else {
    echo "Login inválido!";
    //header("Location: signin.html"); 


// Se a sessão não existir, inicia uma
if (!isset($_SESSION)) session_start();
// Salva os dados encontrados na sessão
$_SESSION['UsuarioID'] = $resultado['id'];
$_SESSION['UsuarioNome'] = $resultado['nome'];
//$_SESSION['UsuarioNivel'] = $resultado['nivel'];
// Redireciona o visitante

}   

? >

I believe the problem is there. Can someone please help me? I can not log in because the password is not compared to the password that is in the database.

    
asked by anonymous 24.10.2017 / 21:59

0 answers