Halt registration when certain conditions are (not) met On registration we have to look up the user-information in a remote database (JSON service), when user is not found there, or when some other error occurs, we want to halt the registration completely.

function foo_user_presave(&amp;$edit, $account, $category) {
  $foo_bar = new FooBarSource($edit["foo_bar_invite_code"]);
  if ($foo_bar-&gt;is_valid()) {
    drupal_set_message(t('Fail'), 'error');
    //What now?
  }
}


Problem is that I fear some records are being written already in, or before hook_user_presave. From the documentation:


  A user account is about to be created or updated.


Is it safe to simply do a drupal_goto() to halt the registration? Would that cause orphaned records in the Database? What about other modules implementing this hook: would they break or be confused?

Is this hook the proper hook to determine if a user can register?
Do hook_form_alter for user registration form, and add extra validation function to the form using #validate like below.

$form['#validate'][] = 'extra_user_validation';


in function extra_user_validation set error after validation. So, that you can avoid the submit process and invoking hooks.

function extra_user_validation($form, &amp;$form_state) {
   // Get the input values of registration form from $form_state['values']
   // Do validation &amp; set error
}


That should work !