Changeset 3010

Show
Ignore:
Timestamp:
07/08/2008 04:09:39 PM (3 months ago)
Author:
Geert
Message:

Cleaning up Captcha_Controller. Using in built in text::random() function. No more special characters, like $ or %, in captcha's anymore. Just a-z0-9.

Location:
trunk/system
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/system/controllers/captcha.php

    r2206 r3010  
    1616 */ 
    1717class Captcha_Controller extends Controller { 
     18 
     19        public $session; 
    1820        public $captcha; 
    19         public $session; 
    2021 
    2122        protected $captcha_code; 
     
    2425        { 
    2526                $this->session = Session::instance(); 
    26  
    2727                $this->captcha = new Captcha; 
    2828 
    29                 // Create a random text string for captcha code. 
     29                // Create and store a random captcha string 
    3030                $this->captcha_code = $this->create_code(); 
    31                 $this->captcha->set_code($this->captcha_code) ; 
     31                $this->captcha->set_code($this->captcha_code); 
     32                $this->session->set('captcha_code', $this->captcha_code); 
    3233 
    33                 // Set the session to store the security code 
    34                 $this->session->set('captcha_code', $this->captcha_code); 
    35                 // Call the library to output the image 
     34                // Output the image 
    3635                $this->captcha->render(); 
    3736        } 
     
    3938        private function create_code() 
    4039        { 
    41                 $num_chars = Config::item('captcha.num_chars'); 
    42  
    43                 if (Config::item('captcha.style') == 'math') 
     40                if (Config::item('captcha.style') === 'math') 
    4441                { 
    4542                        $code = (string) mt_rand(101, 991); 
     
    4744                else 
    4845                { 
    49                         // Character set to use, similar characters removed. 
    50                         $charset = '@2345#6BCDF$GH789KMNPQRT%VWXYZ'; 
    51                         $code = ''; 
    52                         for ($i = 0; $i < $num_chars; $i++) 
    53                         { 
    54                         $code .= substr($charset, mt_rand(0, strlen($charset)-1), 1); 
    55                         } 
     46                        $code = text::random('distinct', Config::item('captcha.num_chars')); 
    5647                } 
    5748 
     
    5950        } 
    6051 
    61 } 
     52} // End Captcha_Controller 
  • trunk/system/libraries/Captcha.php

    r2652 r3010  
    255255                { 
    256256                        $text_color = imageColorAllocate($this->image, mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255), mt_rand($color_limit + 8, 255)); 
    257                         $char = substr($chars, mt_rand(0,15), 1); 
    258                         imageTTFtext($this->image, mt_rand(23, 27), mt_rand(160, 200), mt_rand(-10, $this->width+10), mt_rand(-10, 60), $text_color, $font, $char); 
     257                        $char = substr($chars, mt_rand(0, 15), 1); 
     258                        imageTTFtext($this->image, mt_rand(23, 27), mt_rand(160, 200), mt_rand(-10, $this->width + 10), mt_rand(-10, 60), $text_color, $font, $char); 
    259259                } 
    260260 
     
    353353                for ($i = 0; $i <= $width; $i++) 
    354354                { 
    355                         $red   = $left_color[0] -floor($i*$color0); 
    356                         $green = $left_color[1] -floor($i*$color1); 
    357                         $blue  = $left_color[2] -floor($i*$color2); 
     355                        $red   = $left_color[0] - floor($i * $color0); 
     356                        $green = $left_color[1] - floor($i * $color1); 
     357                        $blue  = $left_color[2] - floor($i * $color2); 
    358358                        $col   = imagecolorallocate($this->image, $red, $green, $blue); 
    359359