I was trying to build an login app
suuccessfully i have stored the data from signup form using password_hash($password , PASSWORD_BCRYPT);
but i have trouble in verifying the password using password_verify()
function
in reg.php
please help me out to get out of this problem
reg.php
<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$email = $request->email;
$password = $request->password;
$conn = new mysqli("localhost", "root", "root", "mydb");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$result=$conn->query("SELECT password FROM login WHERE email='$email'");
$rowcount=mysqli_num_rows($result);
if($rowcount > 0)
{
$row = mysqli_fetch_row($result);//returning the required data correctly
$bool=password_verify($password , $row[0]);//not working
if($bool){
echo "s";
}
}
else{
echo "n";
}
?>
signup.php
<?php
$postdata = file_get_contents("php://input");
$received_data= json_decode($postdata);
$firstname = $received_data->firstname;
$lastname = $received_data->lastname;
$email = $received_data->email;
$password = $received_data->password;
$conn = new mysqli("localhost", "root", "root", "mydb");
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$temp = password_hash($password , PASSWORD_BCRYPT);
$sql = "INSERT INTO login(id,firstname,lastname,email,password)VALUES(NULL,'$firstname','$lastname','$email','$temp')";
if(mysqli_query($conn , $sql))
{
echo "success";
}
else{
echo "failed";
}
?>