Why not integrate this as the else clause of an adapted clause stating at line 65

if force_random

elsif params[:password].present?
  ...
else
  render_api_error
end