Welcome Guest, Not a member yet? Register   Sign In
custom captcha plugin or library, don't know how to name it.
#1

[eluser]hugle[/eluser]
Hello everyone.

I used my captcha everywhere on the site while not using code igniter.

Now I started using it, and need somehow to "reformat" this captcha to work in CI style.

so what is the configuration:
I generate *new* captcha code and store it in the session:

Code:
$rnd_string = "23456789BCDEFGHKLMNP"; // allowed captcha characters
$captcha_code = "";
for ($i = 0; $i < 6; $i ++) { $captcha_code .= $rnd_string[rand(0, strlen($rnd_string)-1)]; }
$this->session->set_userdata('captcha_code', $captcha_code);

and later I had a file, called secure_img.php:
Code:
&lt;?php @session_start();
error_reporting(0);
// send several headers to make sure the image is not cached
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
// send the content type header so the image is displayed properly
header('Content-type: image/png');


$tt = $this->session->userdata('captcha_code');
//$tt = $_SESSION['ss_code'];
//$tt = "ZDLAAA"; //for debugging

$font = "./font.ttf";
$img_width = 198;
$img_height = 21;

$im = imagecreate($img_width,$img_height);
$color1 = ImageColorAllocate($im, 255,255,255); // background color
$color2 = ImageColorAllocate($im, 42,70,111); // font color
$color3 = ImageColorAllocate($im, 191,212,233); // border color
imagerectangle($im, 0, 0, $img_width-1, $img_height-1, $color3);
//imagerectangle($im, 1, 1, $img_width-3, $img_height-3, $color1);
//imagerectangle($im, 0, 10, $img_width, round($img_height/3), $color3);
//imagerectangle($im, 0, 20, $img_width, round($img_height/3*2), $color3);

$rotation_koef = 1;
$position = 50;
$position_y = 16;
$angle = rand(1,50)*$rotation_koef;
$spacing = 4;
for ($c=0;$c<strlen($tt);$c++)
{
    $curr_angle = round(sin($angle)*2);
    $symbol = substr($tt,$c,1);
    $y_adjustment = round($curr_angle/2);
    $box = ImageTTFText($im, 12, $curr_angle, $position, $position_y + $y_adjustment, $color2, $font, $symbol);
    $box = @imageTTFBbox(12,0,$font,$symbol);
    $symbol_width = abs($box[4] - $box[0]);
    $position+= $symbol_width + $spacing;
    $angle+= $rotation_koef;
}


imagepng($im);
ImageDestroy($im);
?&gt;

It used to read data from session ( i commented it out now, since switching to CI style:
Code:
//$tt = $_SESSION['ss_code'];
and the new style should be:
Code:
$tt = $this->session->userdata('captcha_code');

But there should be more changes made in secure_img.php for it to work...
Anyone can help me?

thanks!
#2

[eluser]richthegeek[/eluser]
Just a minor note on CAPTCHA security strengths - you would be better off using a random font and font color (preferably for each letter) to make it harder for letter recognition software to automatically break it.
#3

[eluser]hugle[/eluser]
thanks for your thoughts richthegeek. I've got your mind




Theme © iAndrew 2016 - Forum software by © MyBB