Show
Ignore:
Timestamp:
07/10/2008 11:06:23 AM (5 months ago)
Author:
Geert
Message:

A few minor tweaks to Basic and Alpha Captcha style in order to preserve enough readability and make both styles differ a bit more.

Also changed internal terminology to the "official" convention: http://en.wikipedia.org/wiki/Challenge-response_authentication

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/libraries/drivers/Captcha/Alpha.php

    r3030 r3031  
    11<?php defined('SYSPATH') or die('No direct script access.'); 
    22/** 
    3  * Captcha driver for "basic" style. 
     3 * Captcha driver for "alpha" style. 
    44 * 
    55 * $Id$ 
     
    3939                $this->image_gradient($color1, $color2); 
    4040 
     41                // Add a few random circles 
     42                for ($i = 0, $count = mt_rand(10, Captcha::$config['complexity'] * 3); $i < $count; $i++) 
     43                { 
     44                        $color = imagecolorallocatealpha($this->image, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255), mt_rand(80, 120)); 
     45                        $size = mt_rand(5, Captcha::$config['height'] / 3); 
     46                        imagefilledellipse($this->image, mt_rand(0, Captcha::$config['width']), mt_rand(0, Captcha::$config['height']), $size, $size, $color); 
     47                } 
     48 
    4149                // Calculate character font-size and spacing 
    42                 $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / strlen(Captcha::$answer); 
    43                 $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen(Captcha::$answer)); 
     50                $default_size = min(Captcha::$config['width'], Captcha::$config['height'] * 2) / strlen(Captcha::$response); 
     51                $spacing = (int) (Captcha::$config['width'] * 0.9 / strlen(Captcha::$response)); 
    4452 
    4553                // Background alphabetic character attributes 
     
    4856 
    4957                // Draw each Captcha character with varying attributes 
    50                 for ($i = 0, $strlen = strlen(Captcha::$answer); $i < $strlen; $i++) 
     58                for ($i = 0, $strlen = strlen(Captcha::$response); $i < $strlen; $i++) 
    5159                { 
    5260                        $angle = mt_rand(-40, 20); 
    5361                        // Scale the character size on image height 
    5462                        $size = $default_size / 10 * mt_rand(8, 12); 
    55                         $box = imageftbbox($size, $angle, Captcha::$config['font'], Captcha::$answer[$i]); 
     63                        $box = imageftbbox($size, $angle, Captcha::$config['font'], Captcha::$response[$i]); 
    5664 
    5765                        // Calculate character starting coordinates 
     
    6472 
    6573                        // Write text character to image 
    66                         imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], Captcha::$answer[$i]); 
     74                        imagefttext($this->image, $size, $angle, $x, $y, $color, Captcha::$config['font'], Captcha::$response[$i]); 
    6775 
    6876                        // Draw "ghost" alphabetic character 
    69                         $text_color = imagecolorallocatealpha($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(60, 120)); 
    70                         $char = substr($chars, mt_rand(0,14), 1); 
    71                         imagettftext($this->image, $size, ($angle + (mt_rand(5,10))), ($x - (mt_rand(5,10))), ($y + (mt_rand(5,10))), $text_color, Captcha::$config['font'], $char); 
    72  
     77                        $text_color = imagecolorallocatealpha($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand(70, 120)); 
     78                        $char = substr($chars, mt_rand(0, 14), 1); 
     79                        imagettftext($this->image, $size * 2, mt_rand(-45, 45), ($x - (mt_rand(5, 10))), ($y + (mt_rand(5, 10))), $text_color, Captcha::$config['font'], $char); 
    7380                } 
    7481