Beispiel #1
0
function get_captcha($seed)
{
    $digits = captcha_get_digits();
    // Initialize the RNG
    srand($seed);
    $k = array_rand($digits, 2);
    if (rand(0, 1) == 1) {
        $value = $k[0] + $k[1];
        $text = $digits[$k[0]] . " plus " . $digits[$k[1]];
    } else {
        // Swap when digit 1 is less than digit 2, this makes sure we don't get negative values
        if ($k[1] > $k[0]) {
            $tmp = $k[0];
            $k[0] = $k[1];
            $k[1] = $tmp;
        }
        $value = $k[0] - $k[1];
        $text = $digits[$k[0]] . " minus " . $digits[$k[1]];
    }
    return array('seed' => $seed, 'value' => $value, 'text' => $text);
}
Beispiel #2
0
 /**
  * Validate captcha input.
  *
  * @param string $str The text of the captcha
  *
  * @return bool
  */
 function cinput_check($str)
 {
     $str = $this->input->post('cinput');
     if (!is_numeric($str)) {
         // If the user input is not numeric, convert it to a numeric value
         $this->load->plugin('captcha');
         $digits = captcha_get_digits(true);
         $str = array_search(strtolower($str), $digits);
     }
     if ($str != $this->session->userdata('cinput')) {
         $this->validation->_error_messages['cinput_check'] = 'Incorrect captcha.';
         return false;
     }
     return true;
 }