Title: Duplicate checking
Last modified: June 19, 2019

---

# Duplicate checking

 *  [David Anderson / Team Updraft](https://wordpress.org/support/users/davidanderson/)
 * (@davidanderson)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/duplicate-checking/)
 * Hi,
 * Thank you for this plugin. I encountered the following issue:
 * – If I tick “Login Form” as an “Enabled Form”, then your plugin will check for
   a captcha response on the login form created by [https://wordpress.org/plugins/wp-user-manager/](https://wordpress.org/plugins/wp-user-manager/)–
   but does not output any captcha onto that form. This results in inability to 
   login; you always get the ‘Please solve Captcha correctly’ message.
 * – So, I added an mu-plugin to add the captcha to the form:
 *     ```
       add_action('wpum_before_submit_button_login_form', 'my_wpum_before_submit_button_login_form');
       function my_wpum_before_submit_button_login_form() {
       	do_action( 'anr_captcha_form_field' );
       }
       ```
   
 * That did add it to the form, and the Google Captcha field to what was then POST-
   ed to the WP site upon submitting the form. Unfortunately, this still results
   in ‘Please solve Captcha correctly’ always. So, I investigated why. To investigate
   why, I added some debug logging inside of `anr_verify_captcha()`.
 * – This revealed that `anr_verify_captcha()` was getting called twice. The first
   time, it returns `true`; the second time, false, because what came back in the
   response body from Google was:
 *     ```
       {
         "success": false,
         "error-codes": [
           "timeout-or-duplicate"
         ]
       }
       ```
   
 * i.e. On the second check of the same data, it got an error for being a duplicate.
 * I was able to fix this on the site by writing another mu-plugin function to detect
   duplicates where the first attempt was successful. You might want to adjust that
   directly in your plugin though, to handle such cases. Here’s the mu-plugin function
   I used:
 *     ```
       add_filter('anr_verify_captcha', 'my_anr_verify_captcha', 10, 3);
       function my_anr_verify_captcha($verify, $result, $response) {
   
       	static $seen_response = false;
       	static $seen_verify = null;
   
       	if (true == $seen_verify && false == $verify && $response == $seen_response && !empty($result['error-codes']) && array('timeout-or-duplicate') == $result['error-codes']) {
       		return true;
       	} else {
       		$seen_verify = $verify;
       		$seen_response = $response;
       	}
   
       	return $verify;
   
       }
       ```
   
 * Out of interest, here are the two routes that came into `anr_verify_capture()`,
   causing the duplicate lookup:
 * 1: `require('wp-blog-header.php'), wp, WP->main, do_action_ref_array('wp'), WP_Hook-
   >do_action, WP_Hook->apply_filters, WPUM_Form->process, WPUM_Form_Login->submit_handler,
   wp_authenticate, apply_filters('authenticate'), WP_Hook->apply_filters, anr_captcha_class-
   >login_verify, anr_captcha_class->verify, anr_verify_captcha`
 * 2: `require('wp-blog-header.php'), wp, WP->main, do_action_ref_array('wp'), WP_Hook-
   >do_action, WP_Hook->apply_filters, WPUM_Form->process, WPUM_Form->process, WPUM_Form_Login-
   >done, wp_signon, wp_authenticate, apply_filters('authenticate'), WP_Hook->apply_filters,
   anr_captcha_class->login_verify, anr_captcha_class->verify, anr_verify_captcha`

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Shamim Hasan](https://wordpress.org/support/users/shamim51/)
 * (@shamim51)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/duplicate-checking/#post-11655255)
 * Thank you very much for details.
    I see that plugin is calling `wp_authenticate`
   function twice (`wp_signon` also call this function) which fire `authenticate`
   hook twice.
 * I believe this commit will solve this issue [https://github.com/shamim2883/advanced-nocaptcha-recaptcha/commit/f4356d0831efce65f8081a71e0713d1ceeaf9c5d](https://github.com/shamim2883/advanced-nocaptcha-recaptcha/commit/f4356d0831efce65f8081a71e0713d1ceeaf9c5d)
 * Let me know.
 *  Thread Starter [David Anderson / Team Updraft](https://wordpress.org/support/users/davidanderson/)
 * (@davidanderson)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/duplicate-checking/#post-11655890)
 * [@shamim51](https://wordpress.org/support/users/shamim51/) Thanks, though, I 
   note that the change just caches the last result and doesn’t key it by the response
   being checked. Will that work if you have more than one captcha? I notice that
   your Pro plugin mentions a feature “Allow multiple captcha in same page”.
 *  [Shamim Hasan](https://wordpress.org/support/users/shamim51/)
 * (@shamim51)
 * [6 years, 11 months ago](https://wordpress.org/support/topic/duplicate-checking/#post-11656965)
 * [@davidanderson](https://wordpress.org/support/users/davidanderson/) Thanks again.
   
   Free version also support “Allow multiple captcha in same page”.
 * Result is cached in a static variable which will last one page load. As we cannot
   submit more than one form at a time it will just restrict multiple call to google
   api within that form.
 * When another form will be submitted it will then validate again.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Duplicate checking’ is closed to new replies.

 * ![](https://ps.w.org/advanced-nocaptcha-recaptcha/assets/icon-256x256.png?rev
   =2961544)
 * [CAPTCHA 4WP - Antispam CAPTCHA solution for WordPress](https://wordpress.org/plugins/advanced-nocaptcha-recaptcha/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/advanced-nocaptcha-recaptcha/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/advanced-nocaptcha-recaptcha/)
 * [Active Topics](https://wordpress.org/support/plugin/advanced-nocaptcha-recaptcha/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/advanced-nocaptcha-recaptcha/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/advanced-nocaptcha-recaptcha/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [Shamim Hasan](https://wordpress.org/support/users/shamim51/)
 * Last activity: [6 years, 11 months ago](https://wordpress.org/support/topic/duplicate-checking/#post-11656965)
 * Status: not resolved