? image_captcha/fonts/OLDSH___.TTF Index: captcha.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/captcha/captcha.module,v retrieving revision 1.42.2.24 diff -u -b -B -u -p -r1.42.2.24 captcha.module --- captcha.module 24 Aug 2007 03:16:29 -0000 1.42.2.24 +++ captcha.module 24 Aug 2007 10:57:04 -0000 @@ -168,6 +168,11 @@ function captcha_admin($form_id='', $op= * Form builder function for the general captcha configuration */ function captcha_admin_settings($form_id='') { + // wrong response counter + $form['captcha_wrong_response_counter'] = array( + '#type' => 'markup', + '#value' => t('Already %counter form submissions blocked by CAPTCHA module.', array('%counter' => variable_get('captcha_wrong_response_counter', 0))), + ); // field for the captcha adminstration mode $form['captcha_administration_mode'] = array( '#type' => 'checkbox', @@ -241,6 +246,13 @@ function captcha_admin_settings($form_id '#description' => t('If checked, the user will always have to solve a captcha. If not checked, the captcha check for a form will be omitted during the rest of the session once the user has successfully solved a captcha for that form.'), '#default_value' => variable_get('captcha_persistence', TRUE), ); + // option for logging failed captchas + $form['captcha_log_wrong_responses'] = array( + '#type' => 'checkbox', + '#title' => t('Log wrong captcha responses'), + '#description' => t('When enabled, information about wrong captcha responses will be logged to the watchdog log.'), + '#default_value' => variable_get('captcha_log_wrong_responses', FALSE), + ); // submit button $form['submit'] = array( '#type' => 'submit', @@ -291,6 +303,7 @@ function captcha_admin_settings_submit($ variable_set('captcha_description', $form_values['captcha_description']); } variable_set('captcha_persistence', $form_values['captcha_persistence']); + variable_set('captcha_log_wrong_responses', $form_values['captcha_log_wrong_responses']); drupal_set_message(t('Your captcha settings were saved.'), 'status'); } } @@ -326,7 +339,7 @@ function captcha_form_alter($form_id, &$ $captcha = module_invoke($captcha_point->module, 'captcha', 'generate', $captcha_point->type); if (!$captcha) { //The selected module returned nothing, maybe it is disabled or it's wrong, we should watchdog that and then quit. - watchdog('captcha', + watchdog('CAPTCHA', t('Captcha problem: hook_captcha() of module %module returned nothing when trying to retrieve captcha type %type for form %form_id.', array('%type' => $captcha_point->type, '%module' => $captcha_point->module, '%form_id'=> $form_id)), WATCHDOG_ERROR); @@ -447,7 +460,17 @@ function captcha_validate($form_values) $_SESSION['captcha'][$form_id]['success'] = TRUE; } else { + // set form error form_set_error('captcha_response', t('The answer you entered for the captcha challenge was not correct.')); + // update wrong response counter + variable_set('captcha_wrong_response_counter', variable_get('captcha_wrong_response_counter', 0) + 1); + // log to watchdog if needed + if (variable_get('captcha_log_wrong_responses', FALSE)) { + watchdog('CAPTCHA', + t('%form_id post blocked by CAPTCHA module: user answered "%response", but the solution was "%solution".', + array('%form_id' => $form_id, '%response' => $captcha_response, '%solution'=> $_SESSION['captcha'][$form_id][$captcha_token])), + WATCHDOG_NOTICE); + } } // Unset the solution to prevent reuse of the same captcha solution