我在使用php password_verify时遇到问题,当密码匹配时一切正常,当密码不匹配时,一切似乎崩溃了,在条件不匹配时,我在条件前后添加了一些回显下一个回声没有命中。
if(password_verify($current_password, $hashed_password)){
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "si", $param_password, $param_id);
$param_password = password_hash($password, PASSWORD_DEFAULT);
$param_id = $id;
if(!mysqli_stmt_execute($stmt)){
$resultsArray['response'] = "Something went wrong. Please try again later.";
}
else
{
$resultsArray['response'] = 'Your password has been updated.';
}
mysqli_stmt_close($stmt);
}
else
{
$returnArray['response'] = "Something went wrong. Please try again later.";
}
}
else
{
$returnArray['response'] = 'Current password does not match.';
}
这是我的完整方法:
function updateUsersSettingsPassword($link, $id, $current_password, $password)
{
$resultsArray['response'] = "";
$sqlCheck = "SELECT password, username FROM ClientValidations WHERE idClient = ?";
$sql = "UPDATE ClientValidations SET password = ? WHERE idClient = ?";
if($stmtCheck = mysqli_prepare($link, $sqlCheck)){
mysqli_stmt_bind_param($stmtCheck, "i", $param_id_check);
$param_id_check = $id;
if(mysqli_stmt_execute($stmtCheck)){
mysqli_stmt_store_result($stmtCheck);
if(mysqli_stmt_num_rows($stmtCheck) == 1){
mysqli_stmt_bind_result($stmtCheck, $hashed_password, $username);
if(mysqli_stmt_fetch($stmtCheck)){
if(password_verify($current_password, $hashed_password)){
if($stmt = mysqli_prepare($link, $sql)){
mysqli_stmt_bind_param($stmt, "si", $param_password, $param_id);
$param_password = password_hash($password, PASSWORD_DEFAULT);
$param_id = $id;
if(!mysqli_stmt_execute($stmt)){
$resultsArray['response'] = "Something went wrong. Please try again later.";
}
else
{
$resultsArray['response'] = 'Your password has been updated.';
}
mysqli_stmt_close($stmt);
}
else
{
$returnArray['response'] = "Something went wrong. Please try again later.";
}
}
else
{
$returnArray['response'] = 'Current password does not match.';
}
}
else
{
$returnArray['response'] = "Something went wrong. Please try again later.";
}
} else{
$returnArray['response'] = "Something went wrong. Please try again later.";
}
}else{
$returnArray['response'] = "Something went wrong. Please try again later.";
}
mysqli_stmt_close($stmtCheck);
}
else
{
$returnArray['response'] = "Something went wrong. Please try again later.";
}
return $resultsArray;
}
当$ returnArray ['response']的密码与“当前密码不匹配”相等时,我期望什么?
我在做什么错了?