help with login in php

0

I want to make a login with a previous record, so looking for me I found some tutorials, and this is the code to login:

<?php
session_start();
?>

<?php

$host_db = "localhost";
$user_db = "root";
$pass_db = "123";
$db_name = "proyecto_pre";
$tbl_name = "usuario";

$conexion = new mysqli($host_db, $user_db, $pass_db, $db_name);

if ($conexion->connect_error) {
 die("La conexion falló: " . $conexion->connect_error);
}

$username = $_POST['username'];
$password = $_POST['password'];

$sql = "SELECT * FROM $tbl_name WHERE user = '$username'" ;

$result = $conexion->query($sql);


if ($result->num_rows === 1) {
 $row = $result->fetch_array(MYSQLI_ASSOC);

 if (password_verify($password, $row['password'])) {

 $_SESSION['loggedin'] = true;
 $_SESSION['username'] = $username;
 $_SESSION['start'] = time();
 $_SESSION['expire'] = $_SESSION['start'] + (5 * 60);

 echo "Bienvenido! " . $_SESSION['username'];
 echo "<br><br><a href=panel-control.php>Panel de Control</a>";

 } else {
 echo "Username o Password estan incorrectos.";

 echo "<br><a href='login.php'>Volver a Intentarlo</a>";
 }
}
mysqli_close($conexion)
?>

However, when entering the username and password of my database, the code will send me the message "Username or Password are incorrect." , and when a user enters and incorrect pass the checklogin.php file (the login code) is shown in white.

Does anyone know what the error is? I'm new to php.

    
asked by Raphael 08.06.2016 в 08:22
source

2 answers

1

first check the code well, since the password_verify function receives 2 parameters, the value (password) and the encryption thereof.

boolean password_verify ( string $password , string $hash )
    
answered by 08.06.2016 / 15:11
source
0

I recommend that you do the password encryption check the encrypted password directly

    
answered by 05.07.2016 в 22:21