Making verification code harder to OCR?
| From: | Leif K-Brooks | Date: | Tue, 26 Nov 2002 00:03:57 +0000 |
| Subject: | Making verification code harder to OCR? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-126019@lists.php.net to get a copy of this message | ||
I'm using a verification code image to stop automated sign ups, but two hackers seem to be OCRing it. I've looked through the registration script, and there's definitley no security holes. Does anyone have any ideas as to making the image harder to OCR?
<?php
// seed with microseconds
function make_seed() {
list($usec, $sec) = explode(' ', microtime());
return (float) $sec + ((float) $usec * 100000);
}
$seed = make_seed();
mt_srand($seed);
$dbh = mysql_connect ("", "", "") or exit;
mysql_select_db ("",$dbh) or exit;
$authimage = ImageCreate(40,15);
$bgnum = mt_rand(1,3);
switch($bgnum){
case 1:
$white = ImageColorAllocate($authimage, mt_rand(250,255), mt_rand(250,255), mt_rand(250,255));
break;
case 2:
$green = ImageColorAllocate($authimage, mt_rand(0,5), mt_rand(250,255), mt_rand(0,5));
break;
case 3:
$yellow = ImageColorAllocate($authimage, mt_rand(250,255), mt_rand(250,255), mt_rand(0,5));
break;
}
$black = ImageColorAllocate($authimage, mt_rand(0,30), 0, 0);
header("Content-type: image/png");
$getcode = mysql_fetch_array(mysql_query("select * from signupcodes where id = '$id'"));
imagestring($authimage,mt_rand(4,5),mt_rand(0,5),0,$getcode['code'],$black);
imageline($authimage,0,mt_rand(0,15),40,mt_rand(0,15),$black);
imageline($authimage,0,mt_rand(0,15),40,mt_rand(0,15),$black);
imagepng($authimage);
imagedestroy($authimage);
?>