You are here

function tfa_code_form_validate in Two-factor Authentication (TFA) 6

Same name and namespace in other branches
  1. 7 tfa.pages.inc \tfa_code_form_validate()

Validate handler for TFA login form.

File

./tfa.pages.inc, line 55
tfa.pages.inc

Code

function tfa_code_form_validate($form, &$form_state) {

  // Validate code.
  if ($form_state['clicked_button']['#type'] == 'button') {
    $account = user_load(array(
      'uid' => $form['uid']['#value'],
    ));
    $code = tfa_generate_code($account);
    tfa_store_code($account->uid, $code);
    tfa_tfa_process($account);
  }
  if (empty($form_state['values']['code'])) {
    form_set_error('code', t('Code field is required.'));
  }
  $code = tfa_get_code($form_state['values']['uid']);
  if ($code['code'] != $form_state['values']['code']) {
    form_set_error('code', t('Invalid code.'));

    // Register failure for purposes of flood control.
    flood_register_event('tfa_validate');
  }
}