You are here

function mo_auth_authenticate_user_validate in Google Authenticator / 2 Factor Authentication - 2FA 7

File

./authenticate_user.inc, line 38
This is used to authenticate user during login.

Code

function mo_auth_authenticate_user_validate($form, &$form_state) {

  // $user_api_response = $_SESSION['mo_auth']['user'];
  $challenge_response = $_SESSION['mo_auth']['mo_challenge_response'];
  if ($challenge_response->authType == AuthenticationType::$GOOGLE_AUTHENTICATOR['code'] || $challenge_response->authType == AuthenticationType::$SOFT_TOKEN['code']) {
    $token = $form_state['input']['token'];
    if (empty($token)) {
      $new_form = mo_auth_build_form_with_error_message($form_state, TRUE);
      form_set_error('form', t($new_form['mo_message']));
      unset($new_form['mo_message']);
    }
    elseif (strlen($token) != 6 || !preg_match('/[0-9]/', $token)) {
      $new_form = mo_auth_build_form_with_error_message($form_state);
      form_set_error('form', t($new_form['mo_message']));
      unset($new_form['mo_message']);
    }
  }
  elseif ($challenge_response->authType == AuthenticationType::$SMS['code'] || $challenge_response->authType == AuthenticationType::$SMS_AND_EMAIL['code'] || $challenge_response->authType == AuthenticationType::$OTP_OVER_PHONE['code'] || $challenge_response->authType == AuthenticationType::$OTP_OVER_EMAIL['code']) {
    $token = $form_state['input']['token'];
    if (empty($token)) {
      $new_form = mo_auth_build_form_with_error_message($form_state, TRUE);
      form_set_error('form', t($new_form['mo_message']));
      unset($new_form['mo_message']);
    }
    elseif (!preg_match('/[0-9]/', $token)) {
      $new_form = mo_auth_build_form_with_error_message($form_state);
      form_set_error('form', t($new_form['mo_message']));
      unset($new_form['mo_message']);
    }
  }
  elseif ($challenge_response->authType == AuthenticationType::$KBA['code']) {
    $i = 0;
    foreach ($challenge_response->questions as $question) {
      $i++;
      $ques = $form_state['input']['mo2f_kbaquestion' . $i];
      if ($ques != $question->question) {
        form_set_error('form', t('An error occured while processing your request.'));
        drupal_goto("user");
        break;
      }
    }
  }
}