How can PHP developers ensure that password change functionality requires the user to enter their current password for verification?

To ensure that password change functionality requires the user to enter their current password for verification, PHP developers can implement a form that prompts the user to enter their current password along with the new password. Upon form submission, the PHP code should validate the current password against the one stored in the database before allowing the password update to proceed.

// Assuming $currentPassword and $newPassword are obtained from form input

// Validate current password against the one stored in the database
if(password_verify($currentPassword, $storedPassword)) {
    // Update password in the database
    $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
    // Update $storedPassword with $hashedPassword
    echo "Password updated successfully";
} else {
    echo "Incorrect current password";
}