Log in PHP7

0

I have a mysql bd in which I have a user with an encrypted key. The registration form is this: link

I have a big mess of concepts. My script is as follows:

<?php

    $usuario = stripslashes(trim($_POST['nombre']));;
    $pass = stripslashes(trim($_POST['pass']));;

    if (isset($usuario) && isset($pass)) {
        if (strlen($pass)>= 8) {
                $conexion = mysqli_connect("localhost","root","") or
                        die("conexión errónea");
            mysqli_select_db ($conexion, "mantis")
                        or die ("no se puede seleccionar la BD" );
            //obtenemos el usuario y su contraseña del usuario registrado
            $consulta = "SELECT nombre, contrasena FROM jugadores WHERE EXISTS (nombre='$usuario');";
            $comprobacion = mysqli_query($conexion,$consulta) or die("Autentificación fallida");
            $columnas = $comprobacion->fetch_array(MYSQLI_ASSOC);
          if (password_verify($pass, $columnas['contrasena'])) {
              echo "Enhorabuena, te has logueado correctamente <br>";
          }


            mysqli_close($conexion);
                    }
    }
    else {
        die("Mira, te comento, debes introducir los datos, ¿VALE?");
    }
?>

The user does not authenticate me, always fails, and I do not understand why

    
asked by ras212 24.06.2017 в 23:51
source

1 answer

0

It turns out that the bug was in the query, that I do not remember why my php was generated by myadmin and I copied and pasted it without fixing myself. The correct code is this:

<?php

    $usuario = stripslashes(trim($_POST['nombre']));;
    $pass = stripslashes(trim($_POST['pass']));;

    if (isset($usuario) && isset($pass)) {
        if (strlen($pass)>= 8) {
                $conexion = mysqli_connect("localhost","root","") or
                        die("conexión errónea");
            mysqli_select_db ($conexion, "mantis")
                        or die ("no se puede seleccionar la BD" );
            //obtenemos el usuario y su contraseña del usuario registrado
            $consulta = "SELECT contrasena FROM jugadores WHERE (nombre='$usuario');";
            $comprobacion = mysqli_query($conexion,$consulta) or die("Autentificación fallida");
            $columnas = $comprobacion->fetch_array(MYSQLI_ASSOC);
          if (password_verify($pass, $columnas['contrasena'])) {
              echo "Enhorabuena, te has logueado correctamente <br>";
          }


            mysqli_close($conexion);
                    }
    }
    else {
        die("Mira, te comento, debes introducir los datos, ¿VALE?");
    }
?>
    
answered by 26.06.2017 / 19:09
source