Wikka : URTextCaptchaModule

HomePage :: Categories :: Index :: Changes :: Comments :: Documentation :: Blog :: Login/Register
Most recent edit on 2008-05-17 22:36:54 by BrianKoontz [Added new category]

Additions:
CategoryURModules
CategoryUserContributions


Deletions:
CategoryUserContributions



Edited on 2008-04-17 22:53:18 by BrianKoontz [Added link to docs server]

Additions:
Based on comments the docs server and the URInviteCodeModule here is URTextCaptchaModule. If you use this module, users have to answer one question right before they can register.

Deletions:
Based on comments the docs server and the URInviteCodeModule here is URTextCaptchaModule. If you use this module, users have to answer one question right before they can register.



Edited on 2008-04-17 15:11:22 by NilsLindenberg [0.2 little changes to the docs, no code-change]

Additions:
* @version 0.2
* Display input form with question, answer and encoded question (hidden field).
* Verify if the encoded question exists and if the answer is correct.


Deletions:
* @version 0.1
* Display input form with question, answer and encoded question(hidden field).
* Verify if the encoded question exists and has the correct answer.




Edited on 2008-04-17 15:07:44 by NilsLindenberg [little change]

Additions:
'UR_validation_modules' => 'URTextCaptchaModule',

Deletions:
'UR_validation_modules' => 'URWordpressModule',



Oldest known version of this page was edited on 2008-04-17 10:37:21 by NilsLindenberg [v 0.1]
Page view:

Text Captcha Module for Userregistration




Based on comments the docs server and the 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
/**
 * Require the correct answer for a randomly choosen question for successful registration.
 *
 * Based on ideas from http://www.punbb.fr/forums/viewtopic.php?pid=18554#p18554
 *
 * This UR (user registration) verification module requires the
 * user to enter the correct answer to a question (password) for a successful
 * registration.
 *
 * To implement, set the following in wikka.config.php:
 *    'UR_validation_modules' => 'URTextCaptchaModule'
 *    'UR_captcha_questions' => array(
 *        'First question' => 'Answer',
 *        'Second question' => 'Answer',
 *        ),
 * (If combined with other modules, separate each module with a
 * comma.)
 *
 * @version 0.1
 * @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 '<em class="error">Error in URTextCaptcha module</em>';
        }
        else {
            $questions=array_keys($this->captcha_questions);
            if (FALSE === $questions)
            {
                echo '<em class="error">Error in URTextCaptcha module</em>';
                return;
            }
            //choose random-question
            $nr = rand(0,count($this->captcha_questions)-1);
           
            echo '<label for="UR_captcha">'.$questions[$nr].'</label>'."\n";
            echo '<input type="text" name="UR_captcha" id="UR_captcha" size="10" />'."\n";
            echo '<input name="UR_cap_q" value="'.md5($questions[$nr]).'" type="hidden" />';
        }       
    }

    /**
    * Verify if the encoded question exists and has the correct answer.
    */

    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:
'UR_validation_modules' => 'URWordpressModule',


3a. Formulate some questions + answers and add them to wikka.config.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:

'UR_captcha_questions' => array(
 'Please enter the registration code provided by your admin' => 'registercode',
 ),



CategoryUserContributions
Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.2481 seconds