Php and Mysqli encrypted keys

0

Good, what happens is that I'm super lost with this encrypted keys in php ..... I have a code that already keeps me in the database the keys (already encrypted) my problem now is how to verify them , I have the following code, I guess it will be wrong, and investigated and I can not find a solution, and loaded the password encrypted in a variable, but password_verifi does not work, the number 5 nothing else is a test, since it is the password of an account that I have saved, even so I throw the error is not valid, help ....

<?php

$mysqli= new mysqli("localhost", "root","", "sistema");



$nombre =isset($_POST['usuario']) ? $_POST['usuario'] : null ;
$contra =isset($_POST['contra']) ? $_POST['contra'] : null ;


 $query="SELECT * FROM usuario WHERE usuario='$nombre'";

 $resultado=$mysqli->query($query);

 $row=$resultado->fetch_assoc();

 $hash= $row['password']; 

 echo $hash;


if (password_verify('5', $hash)) {
echo '¡La contraseña es válida!';

} else {
echo 'La contraseña no es válida.';
}
?>
    
asked by Fernando Espinosa 02.03.2017 в 03:31
source

1 answer

0

I suggest you look at the documentation link in the same noteras that for this comparison the hash that you have saved should have been obtained with password_hash() ; test if the value of $row['password'] is the same that you get with password_hash($contra) .

    
answered by 28.03.2017 в 09:59