jackli000
|
分享:
x0
|
[分享] 【官方】基于Discuz! 7.2的随机位数验证码
(GBK-简)
【插件资讯】插件名称:【官方】基于Discuz! 7.2的随机位数验证码 适用版本:其他 语言编码:GBK-简 插件作者:Viswow 版权所属:Discuz 原帖连结: http://www.discuz.net/thr...1-1-1.html【插件说明】鉴于注册机的泛滥,现在修改Discuz验证码为随机位数验证码,本修改在验证模式为:一般的情况下可用,高级验证模式只暂时将验证码修改为了5位,由于高级验证码需要修改的文件更多,所以在观察这个修改的效果之后再决定是否进行修改。修改后,如果启用了验证码随机背景图片,那么请在images\seccode\background中将背景图加长,否则在显示过长验证码的时候会显示的比较奇怪。 GBK版本的修改文件包,UTF8请对应修改。 修改后的效果为:注册的时候验证码随机为2-7位。 效果示例: 后台设置示例: 另外建议大家自行更换images/fonts/en目录中的字体。能够有效的避免验证码被识别。 注意:修改文件较多,修改前请自行备份。 有问题请短消息我。 1.打开templates/default/seccheck.htm 找到
if(!(/[0-9A-Za-z]{4}/.test(seccodeverify))) { 复制代码修改为:
if(!(/[0-9A-Za-z]{1,}/.test(seccodeverify))) { 复制代码2.打开/ajax.php 找到
$seccode = random(6, 1); 复制代码修改为:
$seccode = random($seccodelength*3, 1); 复制代码3.打开include\seccode.class.php 找到:
function display() { $this->type == 2 && !extension_loaded('ming') && $this->type = 0; $this->width = $this->width >= 100 && $this->width <= 200 ? $this->width : 150; $this->height = $this->height >= 50 && $this->height <= 80 ? $this->height : 60; seccodeconvert($this->code); if($this->type < 2 && function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') && function_exists('imagecolorallocate') && function_exists('imagechar') && function_exists('imagecolorsforindex') && function_exists('imageline') && function_exists('imagecreatefromstring') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))) { $this->image(); } elseif($this->type == 2 && extension_loaded('ming')) { $this->flash(); } elseif($this->type == 3) { $this->audio(); } else { $this->bitmap(); } } 复制代码修改为:
function display() { global $seccodelength; $this->type == 2 && !extension_loaded('ming') && $this->type = 0; $this->width = $seccodelength*50; $this->height = $this->height >= 50 && $this->height <= 80 ? $this->height : 60; seccodeconvert($this->code); if($this->type < 2 && function_exists('imagecreate') && function_exists('imagecolorset') && function_exists('imagecopyresized') && function_exists('imagecolorallocate') && function_exists('imagechar') && function_exists('imagecolorsforindex') && function_exists('imageline') && function_exists('imagecreatefromstring') && (function_exists('imagegif') || function_exists('imagepng') || function_exists('imagejpeg'))) { $this->image(); } elseif($this->type == 2 && extension_loaded('ming')) { $this->flash(); } elseif($this->type == 3) { $this->audio(); } else { $this->bitmap(); } } 复制代码找到
imagecopymerge($this->im, $imwm, 0, 0, mt_rand(0, 200 - $this->width), mt_rand(0, 80 - $this->height), imageSX($imwm), imageSY($ imwm), 100); 复制代码修改为:
imagecopymerge($this->im, $imwm, 0, 0, mt_rand(0, 300- $this->width), mt_rand(0, 80 - $this->height), imageSX($imwm), imageSY($ imwm), 100); 复制代码找到:
function ttffont() { $seccode = $this->code; $charset = $GLOBALS['charset']; $seccoderoot = $this->type ? $this->fontpath.'ch/' : $this->fontpath.'en/'; $dirs = opendir($seccoderoot); $seccodettf = array(); while($entry = readdir($dirs)) { if($entry != '.' && $entry != '..' && in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) { $seccodettf[] = $entry; } } if(empty($seccodettf)) { $this->giffont(); return; } $seccodelength = 4; if($this->type && !empty($seccodettf)) { if(strtoupper($charset) != 'UTF-8') { include $this->includepath.'chinese.class.php'; $cvt = new Chinese($charset, 'utf8'); $seccode = $cvt->Convert($seccode); } $seccode = array(substr($seccode, 0, 3), substr($seccode, 3, 3)); $seccodelength = 2; } $widthtotal = 0; for($i = 0; $i < $seccodelength; $i++) { $font[$i]['font'] = $seccoderoot.$seccodettf[array_rand($seccodettf)]; $font[$i]['angle'] = $this->angle ? mt_rand(-30, 30) : 0; $font[$i]['size'] = $this->type ? $this->width / 7 : $this->width / 6; $this->size && $font[$i]['size'] = mt_rand($font[$i]['size'] - $this->width / 40, $font[$i]['size' ] + $this->width / 20); $box = imagettfbbox($font[$i]['size'], 0, $font[$i]['font'], $seccode[$i]); $font[$i]['zheight'] = max($box[1], $box[3]) - min($box[5], $box[7]); $box = imagettfbbox($font[$i]['size'], $font[$i]['angle'], $font[$i]['font'], $seccode[$i]); $font[$i]['height'] = max($box[1], $box[3]) - min($box[5], $box[7]); $font[$i]['hd'] = $font[$i]['height'] - $font[$i]['zheight']; $font[$i]['width'] = (max($box[2], $box[4]) - min($box[0], $box[6])) + mt_rand(0, $this ->width / 8); $font[$i]['width'] = $font[$i]['width'] > $this->width / $seccodelength ? $this->width / $seccodelength : $font[$i][' width']; $widthtotal += $font[$i]['width']; } $x = mt_rand($font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $this->width - $widthtotal); !$this->color && $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); for($i = 0; $i < $seccodelength; $i++) { if($this->color) { $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); $this->shadow && $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]) ; $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); } elseif($this->shadow) { $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]); } $y = $font[0]['angle'] > 0 ? mt_rand($font[$i]['height'], $this->height) : mt_rand($font[$i]['height'] - $font[$i]['hd'], $this->height - $font[$i]['hd']); $this->shadow && imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x + 1, $y + 1, $text_shadowcolor , $font[$i]['font'], $seccode[$i]); imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x, $y, $text_color, $font[$i]['font '], $seccode[$i]); $x += $font[$i]['width']; } } 复制代码修改为:
function ttffont() { $seccode = $this->code; $charset = $GLOBALS['charset']; $seccoderoot = $this->type ? $this->fontpath.'ch/' : $this->fontpath.'en/'; $dirs = opendir($seccoderoot); $seccodettf = array(); while($entry = readdir($dirs)) { if($entry != '.' && $entry != '..' && in_array(strtolower(fileext($entry)), array('ttf', 'ttc'))) { $seccodettf[] = $entry; } } if(empty($seccodettf)) { $this->giffont(); return; } $seccodelength = 4; if($this->type && !empty($seccodettf)) { if(strtoupper($charset) != 'UTF-8') { include $this->includepath.'chinese.class.php'; $cvt = new Chinese($charset, 'utf8'); $seccode = $cvt->Convert($seccode); } $seccode = array(substr($seccode, 0, 3), substr($seccode, 3, 3)); $seccodelength = 2; } $widthtotal = 0; for($i = 0; $i < $seccodelength; $i++) { $font[$i]['font'] = $seccoderoot.$seccodettf[array_rand($seccodettf)]; $font[$i]['angle'] = $this->angle ? mt_rand(-30, 30) : 0; $font[$i]['size'] = $this->type ? $this->width / 7 : $this->width / 6; $this->size && $font[$i]['size'] = mt_rand($font[$i]['size'] - $this->width / 40, $font[$i]['size' ] + $this->width / 20); $box = imagettfbbox($font[$i]['size'], 0, $font[$i]['font'], $seccode[$i]); $font[$i]['zheight'] = max($box[1], $box[3]) - min($box[5], $box[7]); $box = imagettfbbox($font[$i]['size'], $font[$i]['angle'], $font[$i]['font'], $seccode[$i]); $font[$i]['height'] = max($box[1], $box[3]) - min($box[5], $box[7]); $font[$i]['hd'] = $font[$i]['height'] - $font[$i]['zheight']; $font[$i]['width'] = (max($box[2], $box[4]) - min($box[0], $box[6])) + mt_rand(0, $this ->width / 8); $font[$i]['width'] = $font[$i]['width'] > $this->width / $seccodelength ? $this->width / $seccodelength : $font[$i][' width']; $widthtotal += $font[$i]['width']; } $x = mt_rand($font[0]['angle'] > 0 ? cos(deg2rad(90 - $font[0]['angle'])) * $font[0]['zheight'] : 1, $this->width - $widthtotal); !$this->color && $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); for($i = 0; $i < $seccodelength; $i++) { if($this->color) { $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); $this->shadow && $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]) ; $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); } elseif($this->shadow) { $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]); } $y = $font[0]['angle'] > 0 ? mt_rand($font[$i]['height'], $this->height) : mt_rand($font[$i]['height'] - $font[$i]['hd'], $this->height - $font[$i]['hd']); $this->shadow && imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x + 1, $y + 1, $text_shadowcolor , $font[$i]['font'], $seccode[$i]); imagettftext($this->im, $font[$i]['size'], $font[$i]['angle'], $x, $y, $text_color, $font[$i]['font '], $seccode[$i]); $x += $font[$i]['width']; } } 复制代码找到
function giffont() { $seccode = $this->code; $seccodedir = array(); if(function_exists('imagecreatefromgif')) { $seccoderoot = $this->datapath.'gif/'; $dirs = opendir($seccoderoot); while($dir = readdir($dirs)) { if($dir != '.' && $dir != '..' && file_exists($seccoderoot.$dir.'/9.gif')) { $seccodedir[] = $dir; } } } $widthtotal = 0; for($i = 0; $i <= 3; $i++) { $this->imcodefile = $seccodedir ? $seccoderoot.$seccodedir[array_rand($seccodedir)].'/'.strtolower($seccode[$i]).'.gif' : ''; if(!empty($this->imcodefile) && file_exists($this->imcodefile)) { $font[$i]['file'] = $this->imcodefile; $font[$i]['data'] = getimagesize($this->imcodefile); $font[$i]['width'] = $font[$i]['data'][0] + mt_rand(0, 6) - 4; $font[$i]['height'] = $font[$i]['data'][1] + mt_rand(0, 6) - 4; $font[$i]['width'] += mt_rand(0, $this->width / 5 - $font[$i]['width']); $widthtotal += $font[$i]['width']; } else { $font[$i]['file'] = ''; $font[$i]['width'] = 8 + mt_rand(0, $this->width / 5 - 5); $widthtotal += $font[$i]['width']; } } $x = mt_rand(1, $this->width - $widthtotal); for($i = 0; $i <= 3; $i++) { $this->color && $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); if($font[$i]['file']) { $this->imcode = imagecreatefromgif($font[$i]['file']); if($this->size) { $font[$i]['width'] = mt_rand($font[$i]['width'] - $this->width / 20, $font[$i]['width'] + $this-> width / 20); $font[$i]['height'] = mt_rand($font[$i]['height'] - $this->width / 20, $font[$i]['height'] + $this-> width / 20); } $y = mt_rand(0, $this->height - $font[$i]['height']); if($this->shadow) { $this->imcodeshadow = $this->imcode; imagecolorset($this->imcodeshadow, 0 , 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]); imagecopyresized($this->im, $this->imcodeshadow, $x + 1, $y + 1, 0, 0, $font[$i]['width'], $font[$i]['height' ], $font[$i]['data'][0], $font[$i]['data'][1]); } imagecolorset($this->imcode, 0 , $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); imagecopyresized($this->im, $this->imcode, $x, $y, 0, 0, $font[$i]['width'], $font[$i]['height'], $font [$i]['data'][0], $font[$i]['data'][1]); } else { $y = mt_rand(0, $this->height - 20); if($this->shadow) { $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]); imagechar($this->im, 5, $x + 1, $y + 1, $seccode[$i], $text_shadowcolor); } $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); imagechar($this->im, 5, $x, $y, $seccode[$i], $text_color); } $x += $font[$i]['width']; } } 复制代码修改为:
function giffont() { global $seccodelength; $seccode = $this->code; $seccodelength = $seccodelength - 1; $seccodedir = array(); if(function_exists('imagecreatefromgif')) { $seccoderoot = $this->datapath.'gif/'; $dirs = opendir($seccoderoot); while($dir = readdir($dirs)) { if($dir != '.' && $dir != '..' && file_exists($seccoderoot.$dir.'/9.gif')) { $seccodedir[] = $dir; } } } $widthtotal = 0; for($i = 0; $i <= $seccodelength; $i++) { $this->imcodefile = $seccodedir ? $seccoderoot.$seccodedir[array_rand($seccodedir)].'/'.strtolower($seccode[$i]).'.gif' : ''; if(!empty($this->imcodefile) && file_exists($this->imcodefile)) { $font[$i]['file'] = $this->imcodefile; $font[$i]['data'] = getimagesize($this->imcodefile); $font[$i]['width'] = $font[$i]['data'][0] + mt_rand(0, 6) - 4; $font[$i]['height'] = $font[$i]['data'][1] + mt_rand(0, 6) - 4; $font[$i]['width'] += mt_rand(0, $this->width / 5 - $font[$i]['width']); $widthtotal += $font[$i]['width']; } else { $font[$i]['file'] = ''; $font[$i]['width'] = 8 + mt_rand(0, $this->width / 5 - 5); $widthtotal += $font[$i]['width']; } } $x = mt_rand(1, $this->width - $widthtotal); for($i = 0; $i <= $seccodelength; $i++) { $this->color && $this->fontcolor = array(mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255)); if($font[$i]['file']) { $this->imcode = imagecreatefromgif($font[$i]['file']); if($this->size) { $font[$i]['width'] = mt_rand($font[$i]['width'] - $this->width / 20, $font[$i]['width'] + $this-> width / 20); $font[$i]['height'] = mt_rand($font[$i]['height'] - $this->width / 20, $font[$i]['height'] + $this-> width / 20); } $y = mt_rand(0, $this->height - $font[$i]['height']); if($this->shadow) { $this->imcodeshadow = $this->imcode; imagecolorset($this->imcodeshadow, 0 , 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]); imagecopyresized($this->im, $this->imcodeshadow, $x + 1, $y + 1, 0, 0, $font[$i]['width'], $font[$i]['height' ], $font[$i]['data'][0], $font[$i]['data'][1]); } imagecolorset($this->imcode, 0 , $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); imagecopyresized($this->im, $this->imcode, $x, $y, 0, 0, $font[$i]['width'], $font[$i]['height'], $font [$i]['data'][0], $font[$i]['data'][1]); } else { $y = mt_rand(0, $this->height - 20); if($this->shadow) { $text_shadowcolor = imagecolorallocate($this->im, 255 - $this->fontcolor[0], 255 - $this->fontcolor[1], 255 - $this->fontcolor[2]); imagechar($this->im, 5, $x + 1, $y + 1, $seccode[$i], $text_shadowcolor); } $text_color = imagecolorallocate($this->im, $this->fontcolor[0], $this->fontcolor[1], $this->fontcolor[2]); imagechar($this->im, 5, $x, $y, $seccode[$i], $text_color); } $x += $font[$i]['width']; } } 复制代码4.打开include\global.func.php 找到:
function seccodeconvert(&$seccode) { global $seccodedata, $charset; $seccode = substr($seccode, -6); if($seccodedata['type'] == 1) { include_once language('seccode'); $len = strtoupper($charset) == 'GBK' ? 2 : 3; $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3)); $seccode = ''; for($i = 0; $i < 2; $i++) { $seccode .= substr($lang['chn'], $code[$i] * $len, $len); } return; } elseif($seccodedata['type'] == 3) { $s = sprintf('%04s', base_convert($seccode, 10, 20)); $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ'; } else { $s = sprintf('%04s', base_convert($seccode, 10, 24)); $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789'; } $seccode = ''; for($i = 0; $i < 4; $i++) { $unit = ord($s{$i}); $seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57]; } } 复制代码修改为:
function seccodeconvert(&$seccode) { global $seccodedata, $charset,$seccodelength; if($seccodedata['type'] == 1) { include_once language('seccode'); $len = strtoupper($charset) == 'GBK' ? 2 : 3; $code = array(substr($seccode, 0, 3), substr($seccode, 3, 3)); $seccode = ''; for($i = 0; $i < 2; $i++) { $seccode .= substr($lang['chn'], $code[$i] * $len, $len); } return; } elseif($seccodedata['type'] == 3) { $s = sprintf('%04s', base_convert($seccode, 10, 20)); $seccodeunits = 'CEFHKLMNOPQRSTUVWXYZ'; } else { $s = sprintf('%04s', base_convert($seccode, 10, 24)); $seccodeunits = 'BCEFGHJKMPQRTVWXY2346789'; } $seccode = ''; for($i = 0; $i < $seccodelength; $i++) { $unit = ord($s{$i}); $seccode .= ($unit >= 0x30 && $unit <= 0x39) ? $seccodeunits[$unit - 0x30] : $seccodeunits[$unit - 0x57]; } } 复制代码5.打开include\common.inc.php 找到:
if(!$sessionexists) { if($discuz_uid) { if(!($_DSESSION = $db->fetch_first("SELECT $membertablefields, m.styleid FROM {$tablepre}members m WHERE m.uid='$discuz_uid' AND m.password='$discuz_pw' AND m.secques='$discuz_secques'"))) { clearcookies(); } }
if(ipbanned($onlineip)) $_DSESSION['ipbanned'] = 1;
$_DSESSION['sid'] = random(6); $_DSESSION['seccode'] = random(6, 1); } 复制代码在之后增加:
$seccodelength = $_DCOOKIE['secc']; $seccodelength = preg_match('/(\d)/im',$seccodelength,$match); if($seccodelength == 1) { $seccodelength = $match[1]; } else { $seccodelength = 4; }
if($seclevel) { $seccodelength = 5; }
if($seccodelength > 7) { $seccodelength = 7; } elseif($seccodelength < 2) { $seccodelength = 2; } 复制代码
[此文章售价 500 雅币已有 1 人购买]
若发现会员采用欺骗的方法获取财富,请立刻举报,我们会对会员处以2-N倍的罚金,严重者封掉ID!
[ 此文章被jackli000在2012-08-15 14:37重新编辑 ]
|