From 644250f3f3ce43fd74cf52eac73ab277983217e1 Mon Sep 17 00:00:00 2001 From: chicpro Date: Mon, 16 Nov 2015 14:01:03 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BA=A1=EC=B1=A0=20=EB=85=B8=EC=9D=B4?= =?UTF-8?q?=EC=A6=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugin/kcaptcha/kcaptcha.lib.php | 170 ++++++++++++++-------------- plugin/kcaptcha/kcaptcha_config.php | 16 ++- 2 files changed, 97 insertions(+), 89 deletions(-) diff --git a/plugin/kcaptcha/kcaptcha.lib.php b/plugin/kcaptcha/kcaptcha.lib.php index fddea6294..6c0ea5470 100644 --- a/plugin/kcaptcha/kcaptcha.lib.php +++ b/plugin/kcaptcha/kcaptcha.lib.php @@ -35,96 +35,98 @@ class KCAPTCHA{ $alphabet_length=strlen($alphabet); - do{ - /* - // generating random keystring - while(true){ - $this->keystring=''; - for($i=0;$i<$length;$i++){ - $this->keystring.=$allowed_symbols{mt_rand(0,strlen($allowed_symbols)-1)}; - } - if(!preg_match('/cp|cb|ck|c6|c9|rn|rm|mm|co|do|cl|db|qp|qb|dp|ww/', $this->keystring)) break; - } - */ - $font_file=$fonts[mt_rand(0, count($fonts)-1)]; - $font=imagecreatefrompng($font_file); - imagealphablending($font, true); - $fontfile_width=imagesx($font); - $fontfile_height=imagesy($font)-1; - $font_metrics=array(); - $symbol=0; - $reading_symbol=false; + $font_file=$fonts[mt_rand(0, count($fonts)-1)]; + $font=imagecreatefrompng($font_file); + imagealphablending($font, true); + $fontfile_width=imagesx($font); + $fontfile_height=imagesy($font)-1; + $font_metrics=array(); + $symbol=0; + $reading_symbol=false; - // loading font - for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){ - $transparent = (imagecolorat($font, $i, 0) >> 24) == 127; + // loading font + for($i=0;$i<$fontfile_width && $symbol<$alphabet_length;$i++){ + $transparent = (imagecolorat($font, $i, 0) >> 24) == 127; - if(!$reading_symbol && !$transparent){ - $font_metrics[$alphabet{$symbol}]=array('start'=>$i); - $reading_symbol=true; - continue; - } + if(!$reading_symbol && !$transparent){ + $font_metrics[$alphabet{$symbol}]=array('start'=>$i); + $reading_symbol=true; + continue; + } - if($reading_symbol && $transparent){ - $font_metrics[$alphabet{$symbol}]['end']=$i; - $reading_symbol=false; - $symbol++; - continue; - } - } + if($reading_symbol && $transparent){ + $font_metrics[$alphabet{$symbol}]['end']=$i; + $reading_symbol=false; + $symbol++; + continue; + } + } - $img=imagecreatetruecolor($width, $height); - imagealphablending($img, true); - $white=imagecolorallocate($img, 255, 255, 255); - $black=imagecolorallocate($img, 0, 0, 0); + $img=imagecreatetruecolor($width, $height); + imagealphablending($img, true); + $white=imagecolorallocate($img, 255, 255, 255); + $black=imagecolorallocate($img, 0, 0, 0); - imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white); + imagefilledrectangle($img, 0, 0, $width-1, $height-1, $white); - // draw text - $x=1; - for($i=0;$ikeystring);$i++){ - $m=$font_metrics[$this->keystring{$i}]; + // draw text + $x=1; + $odd=mt_rand(0,1); + if($odd==0) $odd=-1; + for($i=0;$i<$length;$i++){ + $m=$font_metrics[$this->keystring{$i}]; - $y=mt_rand(-$fluctuation_amplitude, $fluctuation_amplitude)+($height-$fontfile_height)/2+2; + $y=(($i%2)*$fluctuation_amplitude - $fluctuation_amplitude/2)*$odd + + mt_rand(-round($fluctuation_amplitude/3), round($fluctuation_amplitude/3)) + + ($height-$fontfile_height)/2; - if($no_spaces){ - $shift=0; - if($i>0){ - $shift=10000; - for($sy=7;$sy<$fontfile_height-20;$sy+=1){ - for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){ - $rgb=imagecolorat($font, $sx, $sy); - $opacity=$rgb>>24; - if($opacity<127){ - $left=$sx-$m['start']+$x; - $py=$sy+$y; - if($py>$height) break; - for($px=min($left,$width-1);$px>$left-12 && $px>=0;$px-=1){ - $color=imagecolorat($img, $px, $py) & 0xff; - if($color+$opacity<190){ - if($shift>$left-$px){ - $shift=$left-$px; - } - break; - } - } - break; - } - } - } - if($shift==10000){ - $shift=mt_rand(4,6); - } + if($no_spaces){ + $shift=0; + if($i>0){ + $shift=10000; + for($sy=3;$sy<$fontfile_height-10;$sy+=1){ + for($sx=$m['start']-1;$sx<$m['end'];$sx+=1){ + $rgb=imagecolorat($font, $sx, $sy); + $opacity=$rgb>>24; + if($opacity<127){ + $left=$sx-$m['start']+$x; + $py=$sy+$y; + if($py>$height) break; + for($px=min($left,$width-1);$px>$left-200 && $px>=0;$px-=1){ + $color=imagecolorat($img, $px, $py) & 0xff; + if($color+$opacity<170){ // 170 - threshold + if($shift>$left-$px){ + $shift=$left-$px; + } + break; + } + } + break; + } + } + } + if($shift==10000){ + $shift=mt_rand(4,6); + } - } - }else{ - $shift=1; - } - imagecopy($img, $font, $x-$shift, $y, $m['start'], 1, $m['end']-$m['start'], $fontfile_height); - $x+=$m['end']-$m['start']-$shift; - } - }while($x>=$width-10); // while not fit in canvas + } + }else{ + $shift=1; + } + imagecopy($img, $font, $x-$shift, $y, $m['start'], 1, $m['end']-$m['start'], $fontfile_height); + $x+=$m['end']-$m['start']-$shift; + } + + //noise + $white=imagecolorallocate($font, 255, 255, 255); + $black=imagecolorallocate($font, 0, 0, 0); + for($i=0;$i<(($height-30)*$x)*$white_noise_density;$i++){ + imagesetpixel($img, mt_rand(0, $x-1), mt_rand(10, $height-15), $white); + } + for($i=0;$i<(($height-30)*$x)*$black_noise_density;$i++){ + imagesetpixel($img, mt_rand(0, $x-1), mt_rand(10, $height-15), $black); + } $center=$x/2; @@ -235,21 +237,17 @@ class KCAPTCHA{ // 캡챠 HTML 코드 출력 function captcha_html($class="captcha") { - if(is_mobile()) - $class .= ' m_captcha'; - $html .= "\n".''; //$html .= "\n".''; $html .= "\n".''; $html .= "\n".'
'; $html .= "\n".''; - if (is_mobile()) $html .= ''; //$html .= "\n".''; $html .= "\n".''; - if (!is_mobile()) $html .= "\n".''; + $html .= "\n".''; $html .= "\n".''; $html .= ''; - $html .= "\n".'자동등록방지 숫자를 순서대로 입력하세요.'; + $html .= "\n".'자동등록방지 영숫자를 순서대로 입력하세요.'; $html .= "\n".'
'; return $html; } diff --git a/plugin/kcaptcha/kcaptcha_config.php b/plugin/kcaptcha/kcaptcha_config.php index 7d8f70f02..cd42a3a46 100644 --- a/plugin/kcaptcha/kcaptcha_config.php +++ b/plugin/kcaptcha/kcaptcha_config.php @@ -6,21 +6,31 @@ $alphabet = "0123456789abcdefghijklmnopqrstuvwxyz"; # do not change without chan # symbols used to draw CAPTCHA $allowed_symbols = "0123456789"; #digits +//$allowed_symbols = "0123456789abcdef"; #digits // 스캔 방지를 위하여 abcdef 추가 151029 15:00 +//$allowed_symbols = "abcdeghkmnpqsuvxyz"; #digits //$allowed_symbols = "23456789abcdeghkmnpqsuvxyz"; #alphabet without similar symbols (o=0, 1=l, i=j, t=f) # folder with fonts -$fontsdir = 'fonts'; +$fontsdir = 'fonts'; # CAPTCHA string length //$length = mt_rand(5,6); # random 5 or 6 $length = 6; # CAPTCHA image size (you do not need to change it, whis parameters is optimal) -$width = 120; +$width = 160; $height = 60; # symbol's vertical fluctuation amplitude divided by 2 -$fluctuation_amplitude = 5; +//$fluctuation_amplitude = 5; +//$fluctuation_amplitude = 11; // 파동&진폭 151028 14:00 +$fluctuation_amplitude = 5; // 파동&진폭 원래대로 151029 15:00 + +#noise +//$white_noise_density=0; // no white noise +$white_noise_density=1/6; +//$black_noise_density=0; // no black noise +$black_noise_density=1/20; # increase safety by prevention of spaces between symbols $no_spaces = false;