Login using PDO

1

I'm developing a login system with pdo for learning, but it always accuses the password.

Follow the code:

<?php
    session_start();
    include "../../lib/inc_con.php";

    $pdo=conectar();

    $validarlogin = $pdo->query("SELECT * FROM usuarios WHERE email = :email and senha = :senha");
    $validarlogin = $pdo->prepare("SELECT * FROM usuarios WHERE email = :email and senha = :senha");

    $validarlogin->bindValue(":email", $_POST['email']);
    $validarlogin->bindValue(":senha", md5($_POST['email']));
    $validarlogin->execute();

    if($validarlogin->rowCount() == 1)
    {
        while($ln = $validarlogin->fetch(PDO::FETCH_ASSOC))
        {
            $_SESSION['loginempresa'] = $ln['email'];
            $_SESSION['senhaempresa'] = $ln['senha'];
            $_SESSION['nomeempresa'] = $ln['nome'];
            $_SESSION['nascimentoempresa'] = $ln['nascimento'];
            $_SESSION['cidadeempresa'] = $ln['cidade'];
            $_SESSION['estadoempresa'] = $ln['estado'];
            $_SESSION['nivelempresa'] = $ln['nivel'];
            $_SESSION['fotoempresa'] = $ln['foto'];
            $_SESSION['idempresa'] = $ln['id'];

            echo "<script>alert('Logado Com Sucesso!');
                top.location.href='../../index.php';
                </script>";
        };
      }
    else
    {
        echo "<script>alert('Usuarios Ou Senha Incorretos!');
            top.location.href='detLogin.php';
            </script>";
    }
?>
    
asked by anonymous 19.12.2015 / 01:12

1 answer

5

Change this line:

$validarlogin->bindValue(":senha", md5($_POST['email']));

To:

$validarlogin->bindValue(":senha", md5($_POST['senha']));

You are using the encryption algorithm in the 'email' field and not the 'password' field.

    
19.12.2015 / 01:25