diff --git a/honeypot.module b/honeypot.module index 83e45ca..56ba388 100644 --- a/honeypot.module +++ b/honeypot.module @@ -8,6 +8,7 @@ use Drupal\Core\Form\FormStateInterface; use Drupal\Component\Utility\Crypt; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Component\Utility\Random; /** * Implements hook_help(). @@ -154,7 +155,7 @@ function honeypot_add_form_protection(&$form, FormStateInterface $form_state, ar ], ], '#type' => 'textfield', - '#title' => t('Leave this field blank'), + '#title' => _honeypot_get_field_title(), '#size' => 20, '#weight' => 100, '#attributes' => ['autocomplete' => 'off'], @@ -266,6 +267,63 @@ function _honeypot_log($form_id, $type) { } } +/** + * Generate a title for the honeypot element. + */ +function _honeypot_get_field_title() { + $length = mt_rand(4, 15); + mt_srand((double) microtime() * 1000000); + $vowels = [ + "a", + "e", + "i", + "o", + "u", + ]; + $cons = [ + "b", + "c", + "d", + "g", + "h", + "j", + "k", + "l", + "m", + "n", + "p", + "r", + "s", + "t", + "u", + "v", + "w", + "tr", + "cr", + "br", + "fr", + "th", + "dr", + "ch", + "ph", + "wr", + "st", + "sp", + "sw", + "pr", + "sl", + "cl", + "sh", + ]; + $num_vowels = count($vowels); + $num_cons = count($cons); + $word = ''; + while (strlen($word) < $length) { + $word .= $cons[mt_rand(0, $num_cons - 1)] . $vowels[mt_rand(0, $num_vowels - 1)]; + } + return substr($word, 0, $length); +} + /** * Look up the time limit for the current user. *