From 491d3956a4f1bc6ce5501bcc0449007a16514288 Mon Sep 17 00:00:00 2001 From: xue <> Date: Wed, 29 Aug 2007 03:03:30 +0000 Subject: implemented CAPTCHA image generation. --- framework/Web/UI/WebControls/assets/captcha.php | 60 +++++++++++++++++++++--- framework/Web/UI/WebControls/assets/verase.ttf | Bin 0 -> 60280 bytes 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 framework/Web/UI/WebControls/assets/verase.ttf (limited to 'framework/Web/UI/WebControls/assets') diff --git a/framework/Web/UI/WebControls/assets/captcha.php b/framework/Web/UI/WebControls/assets/captcha.php index aa3fdcc0..a722772b 100644 --- a/framework/Web/UI/WebControls/assets/captcha.php +++ b/framework/Web/UI/WebControls/assets/captcha.php @@ -1,11 +1,17 @@ =6 && isset($_GET['length']) && (int)$_GET['length']>=4 && isset($_GET['case'])) +{ + require_once(dirname(__FILE__).'/captcha_key.php'); + $publicKey=$_GET['pk']; + $tokenLength=(int)$_GET['length']; + $caseSensitive=!empty($_GET['case']); + $token=generateToken($publicKey,$privateKey,$tokenLength,$caseSensitive); +} else - echo $privateKey; + $token='error'; + +displayToken($token); function generateToken($publicKey,$privateKey,$tokenLength,$caseSensitive) { @@ -16,7 +22,7 @@ function generateToken($publicKey,$privateKey,$tokenLength,$caseSensitive) function hash2string($hex,$alphabet='') { if(strlen($alphabet)<2) - $alphabet='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $alphabet='234578adefhijmnrtABDEFGHJLMNQRT'; $hexLength=strlen($hex); $base=strlen($alphabet); $result=''; @@ -32,4 +38,46 @@ function hash2string($hex,$alphabet='') return $result; } +function displayToken($token) +{ + $length=strlen($token); + $width=45*$length; + $height=70; + $image=imagecreatetruecolor($width,$height); + $font=dirname(__FILE__).DIRECTORY_SEPARATOR.'verase.ttf'; + $vred=rand(0,100); + $vgreen=rand(0,100); + $vblue=rand(0,100); + for($x=0;$x<$width;++$x) + { + for($y=0;$y<$height;++$y) + { + $vred+=rand(-2,2); + $vgreen+=rand(-2,2); + $vblue+=rand(-2,2); + if($vred<0) $vred=0; if($vred>150) $vred=75; + if($vgreen<0) $vgreen=0; if($vgreen>150) $vgreen=75; + if($vblue<0) $vblue=0; if($vblue>150) $vblue=75; + $col = imagecolorallocate($image, $vred, $vgreen, $vblue); + imagesetpixel($image, $x, $y, $col); + imagecolordeallocate($image, $col); + } + } + + imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); + for($i=0;$i<$length;$i++) + { + $vred = rand(150, 240); + $vgreen = rand(150, 240); + $vblue = rand(150, 240); + $col = imagecolorallocate($image, $vred, $vgreen, $vblue); + $char = $token[$i]; + imagettftext($image, rand(40, 50), rand(-10, 20), 13 + (40 * $i), rand(50, imagesy($image) - 10), $col, $font, $char); + imagecolordeallocate($image, $col); + } + imagefilter($image,IMG_FILTER_GAUSSIAN_BLUR); + imagepng($image); + imagedestroy($image); +} + ?> \ No newline at end of file diff --git a/framework/Web/UI/WebControls/assets/verase.ttf b/framework/Web/UI/WebControls/assets/verase.ttf new file mode 100644 index 00000000..4b4ecc66 Binary files /dev/null and b/framework/Web/UI/WebControls/assets/verase.ttf differ -- cgit v1.2.3