so i have a database with phpmyadmin and there is password column there. I want to make a script that can change password and if the current password is the same as the password in the database, the change will succeed. but if the current password doesnt match the password in the database, change password fail.
when i try it i always get wrong password/failed even though the current password is the same as the password in the database. i check it using Postman
this is the output from postmanpostman
this is my database database
and this is my PHP script
<?php
if ($_SERVER['REQUEST_METHOD']=='POST'){
$id = $_POST['id'];
$currentpassword = $_POST['currentpassword'];
$newpassword = $_POST['newpassword'];
require_once 'connect.php';
$sql = "SELECT * FROM user_account WHERE id='$id' ";
$response = mysqli_query($conn, $sql);
//echo mysqli_num_rows($response);
if(mysqli_num_rows($response) > 0){
$row = mysqli_fetch_assoc($response);
if (password_verify($currentpassword, $row['password']) ){
$updatepass = "UPDATE user_account SET password='$newpassword' WHERE id='$id' ";
if(mysqli_query($conn, $updatepass)) {
$result["success"] = "1";
$result["message"] = "success";
echo json_encode($result);
mysqli_close($conn);
}
else{
$result["success"] = "0";
$result["message"] = "error!";
echo json_encode($result);
mysqli_close($conn);
}
}else{
$result['success'] = "0";
$result['message'] = "Wrong password.";
echo json_encode($result);
mysqli_close($conn);
}
}
}
?>