diff --git a/src/Element/Captcha.php b/src/Element/Captcha.php index 72af13b..dc67cf6 100644 --- a/src/Element/Captcha.php +++ b/src/Element/Captcha.php @@ -75,6 +75,11 @@ public static function processCaptchaElement(&$element, FormStateInterface $form else { // Generate a new CAPTCHA session if we could not reuse one from a posted form. $captcha_sid = _captcha_generate_captcha_session($this_form_id, CAPTCHA_STATUS_UNSOLVED); + $captcha_token = md5(mt_rand()); + db_update('captcha_sessions') + ->fields(['token' => $captcha_token]) + ->condition('csid', $captcha_sid) + ->execute(); } // Store CAPTCHA session ID as hidden field. @@ -88,14 +93,18 @@ public static function processCaptchaElement(&$element, FormStateInterface $form ]; // Additional one time CAPTCHA token: store in database and send with form. - $captcha_token = md5(mt_rand()); + /* $captcha_token = md5(mt_rand()); db_update('captcha_sessions') ->fields(['token' => $captcha_token]) ->condition('csid', $captcha_sid) - ->execute(); + ->execute();*/ + $captcha_token = db_query( + "SELECT token FROM {captcha_sessions} WHERE csid = :csid", + [':csid' => $captcha_sid] + )->fetchField(); $element['captcha_token'] = [ - '#type' => 'hidden', - '#value' => $captcha_token, + '#type' => 'hidden', + '#value' => $captcha_token, ]; // Get implementing module and challenge for CAPTCHA.