Changeset 3010
- Timestamp:
- 07/08/2008 04:09:39 PM (3 months ago)
- Location:
- trunk/system
- Files:
-
- 2 modified
-
controllers/captcha.php (modified) (5 diffs)
-
libraries/Captcha.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/system/controllers/captcha.php
r2206 r3010 16 16 */ 17 17 class Captcha_Controller extends Controller { 18 19 public $session; 18 20 public $captcha; 19 public $session;20 21 21 22 protected $captcha_code; … … 24 25 { 25 26 $this->session = Session::instance(); 26 27 27 $this->captcha = new Captcha; 28 28 29 // Create a random text string for captcha code.29 // Create and store a random captcha string 30 30 $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); 32 33 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 36 35 $this->captcha->render(); 37 36 } … … 39 38 private function create_code() 40 39 { 41 $num_chars = Config::item('captcha.num_chars'); 42 43 if (Config::item('captcha.style') == 'math') 40 if (Config::item('captcha.style') === 'math') 44 41 { 45 42 $code = (string) mt_rand(101, 991); … … 47 44 else 48 45 { 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')); 56 47 } 57 48 … … 59 50 } 60 51 61 } 52 } // End Captcha_Controller -
trunk/system/libraries/Captcha.php
r2652 r3010 255 255 { 256 256 $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); 259 259 } 260 260 … … 353 353 for ($i = 0; $i <= $width; $i++) 354 354 { 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); 358 358 $col = imagecolorallocate($this->image, $red, $green, $blue); 359 359
