=====Text Captcha Module for Userregistration===== {{lastedit}} Based on comments the docs server and the [[Docs:UserRegistrationValidationFramework | URInviteCodeModule]] here is URTextCaptchaModule. If you use this module, users have to answer one question right before they can register. ====Install==== 1. Save the following as **libs/UR/URTextCaptchaModule/URTextCaptchaModule.php**: %%(php) 'URTextCaptchaModule' * 'UR_captcha_questions' => array( * 'First question' => 'Answer', * 'Second question' => 'Answer', * ), * (If combined with other modules, separate each module with a * comma.) * * @version 0.2 * @see libs/userregistration.class.php * @see URAuth, URAuthTmpl * * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License * @filesource * * @author {@link http://wikkawiki.org/BrianKoontz Brian Koontz} (Invite Code module) * @author {@link http://wikkawiki.org/NilsLindenberg NilsLindenberg} (extended) * * @see libs/userregistration.class.php * @see URAuth, URAuthTmpl * * @todo i18n * @todo Add number to the md5 to get some more randomness? */ include_once('libs/userregistration.class.php'); class URTextCaptchaModule extends URAuthTmpl { /** * Array for questions (key) and answers (value) for the captcha. */ var $captcha_questions; /** * Constructor. Load questions and answers from the config file. */ function URTextCaptchaModule(&$wakka) { $this->URAuthTmpl($wakka); if(isset($wakka->config['UR_captcha_questions'])) { $this->captcha_questions = $wakka->config['UR_captcha_questions']; } } /** * Display input form with question, answer and encoded question (hidden field). */ function URAuthTmplDisplay() { if(!isset($this->captcha_questions) || !is_array($this->captcha_questions)) { echo 'Error in URTextCaptcha module'; } else { $questions=array_keys($this->captcha_questions); if (FALSE === $questions) { echo 'Error in URTextCaptcha module'; return; } //choose random-question $nr = rand(0,count($this->captcha_questions)-1); echo ''."\n"; echo ''."\n"; echo ''; } } /** * Verify if the encoded question exists and if the answer is correct. */ function URAuthTmplVerify() { if(!isset($this->captcha_questions)) { return FALSE; } if(isset($_POST['UR_captcha']) && isset($_POST['UR_cap_q'])) { foreach ($this->captcha_questions as $k => $v) { if (md5($k) == $_POST['UR_cap_q']) { if ($v == $_POST['UR_captcha']) return TRUE; } } } return FALSE; } } ?> %% 2. Activate it: in **wikka.config.php** add: %%(php) 'UR_validation_modules' => 'URTextCaptchaModule', %% 3a. Formulate some questions + answers and add them to **wikka.config.php** %%(php) 'UR_captcha_questions' => array( 'First question' => 'Answer', 'Second question' => 'Answer', ), %% 3b. Of course it is possible to use it with only an regiter code, too: %%(php) 'UR_captcha_questions' => array( 'Please enter the registration code provided by your admin' => 'registercode', ), %% ---- CategoryURModules CategoryUserContributions