Craft 3 validate new password in change password
I believe what you're looking for is this:

if ($newPassword != $confirmPassword){
    Craft::$app-&gt;session-&gt;setError('Confirm password does not match new password');
    $event-&gt;isValid = false;
}


Setting isValid to false will stop further processing of that element (the user in this case).