Show
Ignore:
Timestamp:
07/08/2008 04:09:39 PM (5 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.

Files:
1 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