Skip to content
This repository was archived by the owner on Apr 1, 2019. It is now read-only.

Correction 3.1 #14

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified README.md
100644 → 100755
Empty file.
12 changes: 6 additions & 6 deletions classes/captcha.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function __construct($group = NULL)
public function update_response_session()
{
// Store the correct Captcha response in a session
Session::instance()->set('captcha_response', sha1(strtoupper($this->response)));
Session::instance()->set('captcha_response', sha1(utf8::strtoupper($this->response)));
}

/**
Expand All @@ -178,7 +178,7 @@ public static function valid($response)
return TRUE;

// Challenge result
$result = (bool) (sha1(strtoupper($response)) === Session::instance()->get('captcha_response'));
$result = (bool) (sha1(utf8::strtoupper($response)) === Session::instance()->get('captcha_response'));

// Increment response counter
if ($counted !== TRUE)
Expand Down Expand Up @@ -434,10 +434,10 @@ public function image_render($html)
return '<img src="'.url::site('captcha/'.Captcha::$config['group']).'" width="'.Captcha::$config['width'].'" height="'.Captcha::$config['height'].'" alt="Captcha" class="captcha" />';

// Send the correct HTTP header
Request::instance()->headers['Content-Type'] = 'image/'.$this->image_type;
Request::instance()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0';
Request::instance()->headers['Pragma'] = 'no-cache';
Request::instance()->headers['Connection'] = 'close';
Request::current()->headers['Content-Type'] = 'image/'.$this->image_type;
Request::current()->headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0';
Request::current()->headers['Pragma'] = 'no-cache';
Request::current()->headers['Connection'] = 'close';

// Pick the correct output function
$function = 'image'.$this->image_type;
Expand Down
Empty file modified classes/captcha/alpha.php
100644 → 100755
Empty file.
10 changes: 5 additions & 5 deletions classes/captcha/basic.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ public function render($html = TRUE)
}

// Calculate character font-size and spacing
$default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (strlen($this->response) + 1);
$spacing = (int) (Captcha::$config['width'] * 0.9 / strlen($this->response));
$default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / (utf8::strlen($this->response) + 1);
$spacing = (int) (Captcha::$config['width'] * 0.9 / utf8::strlen($this->response));

// Draw each Captcha character with varying attributes
for ($i = 0, $strlen = strlen($this->response); $i < $strlen; $i++)
for ($i = 0, $strlen = utf8::strlen($this->response); $i < $strlen; $i++)
{
// Use different fonts if available
$font = Captcha::$config['fontpath'].Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];
Expand All @@ -66,14 +66,14 @@ public function render($html = TRUE)

// Scale the character size on image height
$size = $default_size / 10 * mt_rand(8, 12);
$box = imageftbbox($size, $angle, $font, $this->response[$i]);
$box = imageftbbox($size, $angle, $font, utf8::substr($this->response, $i, 1));

// Calculate character starting coordinates
$x = $spacing / 4 + $i * $spacing;
$y = Captcha::$config['height'] / 2 + ($box[2] - $box[5]) / 4;

// Write text character to image
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, $this->response[$i]);
imagefttext($this->image, $size, $angle, $x, $y, $color, $font, utf8::substr($this->response, $i, 1));
}

// Output
Expand Down
6 changes: 3 additions & 3 deletions classes/captcha/black.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function render($html = TRUE)
$font = Captcha::$config['fontpath'].Captcha::$config['fonts'][array_rand(Captcha::$config['fonts'])];

// Draw the character's white shadows
$size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / strlen($this->response));
$angle = mt_rand(-15 + strlen($this->response), 15 - strlen($this->response));
$x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * strlen($this->response));
$size = (int) min(Captcha::$config['height'] / 2, Captcha::$config['width'] * 0.8 / utf8::strlen($this->response));
$angle = mt_rand(-15 + strlen($this->response), 15 - utf8::strlen($this->response));
$x = mt_rand(1, Captcha::$config['width'] * 0.9 - $size * utf8::strlen($this->response));
$y = ((Captcha::$config['height'] - $size) / 2) + $size;
$color = imagecolorallocate($this->image, 255, 255, 255);
imagefttext($this->image, $size, $angle, $x + 1, $y + 1, $color, $font, $this->response);
Expand Down
Empty file modified classes/captcha/math.php
100644 → 100755
Empty file.
Empty file modified classes/captcha/riddle.php
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions classes/captcha/word.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public function generate_challenge()
foreach ($words as $word)
{
// ...until we find one of the desired length
if (abs(Captcha::$config['complexity'] - strlen($word)) < 2)
return strtoupper($word);
if (abs(Captcha::$config['complexity'] - utf8::strlen($word)) < 2)
return utf8::strtoupper($word);
}

// Return any random word as final fallback
Expand Down
3 changes: 2 additions & 1 deletion classes/controller/captcha.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ class Controller_Captcha extends Controller {
*
* @param string $group Config group name
*/
public function action_index($group = 'default')
public function action_index()
{
// Output the Captcha challenge resource (no html)
// Pull the config group name from the URL
$group = $this->request->param('group', 'default');
Captcha::instance($group)->render(FALSE);
}

Expand Down
Empty file modified config/captcha.php
100644 → 100755
Empty file.
Empty file modified fonts/DejaVuSerif.ttf
100644 → 100755
Empty file.
Empty file modified fonts/LICENSE
100644 → 100755
Empty file.
Empty file modified init.php
100644 → 100755
Empty file.