You are here: Re: Security Needed! « All PHP « IT news, forums, messages
Re: Security Needed!

Posted by Jasen Betts on 02/18/06 07:29

On 2006-02-17, Blackhawk@idonthaveone.com <Blackhawk@idonthaveone.com> wrote:
> I have a guest book and someone is raising hell with me on it. I must
> receive 50 entries a day and all bogus. Don't know why they have
> picked my site but I have to do something now to correct the on going
> problem.
>
> I need a security feature for my guest book. I have seen some on other
> boards where there is a series a letters and or numbers only the human
> eye can pick out and enter in order to submit an entry into the guest
> book. Can someone direct me to the source of this security script in
> php, please!

here's one I wrote this afternoon, just to see if it could be done
efficently enough in PHP...

all the trig (sin()) calls had me worried, but my fears were unfounded trig
is much faster on a pentium than it is on an 80386 which was the last time
I played with trig-intensive code.

when it comes time to validate you may need to map 0 to O and I to 1

this code needs the GD library and a TTF font for the text, I used one that
was already installed here, but you may need to upload one to your web server.


<?php // human passgate version 1.0
// generate a random text image and store the code in $_SESSION['code']
session_start();
$iw=500; // width of the text
$ih=100; // height of the text
$r=30; //distortion radius - final image is this much larger in all directions
$f=100; //fraggedness amount of distortion

$str=strtoupper(base_convert(rand(1679616,60466176),10,36));
$_SESSION['code']=$str;

$im = @imagecreate($iw+4*$r,$ih+4*$r)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0,0);
$box_color = imagecolorallocate($im,255,255,255);
imagefilledrectangle($im,$r*2,$r*2,$r*2+$iw,$r*2+$ih,$box_color);
$tc = imagecolorallocate($im, 233, 14, 91);
imagefttext ($im,$ih, 0, 2*$r,$ih+2*$r, $tc,
"/var/lib/defoma/gs.d/dirs/fonts/FreeSans.ttf" ,
$str );

$fr=$f/$r/20000
$pxx0=rand(0,360)/180*pi();
$pxy0=rand(0,360)/180*pi();
$pyx0=rand(0,360)/180*pi();
$pyy0=rand(0,360)/180*pi();
$fxx=rand(150,200)*$fr;
$fxy=rand(150,200)*$fr;
$fyx=rand(150,200)*$fr;
$fyy=rand(150,200)*$fr;

$maxx=$iw+2*$r;
$maxy=$ih+2*$r;

$img=imagecreate($maxx,$maxy);

$pxx=$pxx0;
$pxy=$pxy0;

$ga = imagecolorallocate($img, 0, 0,0);
$go = imagecolorallocate($img,255,255,255);
$gf = imagecolorallocate($img, 233, 14, 91);

for($x=0;$x<$maxx;$x++)
{
$pyx=$pyx0;
$pyy=$pyy0;
$oxx=sin($pxx+=$fxx);
$oyy=sin($pxy+=$fxy);
for($y=0;$y<$maxy;$y++)
{
$px=$oxx*sin($pyx+=$fyx)*$r+$r;
$py=$oyy*sin($pyy+=$fyy)*$r+$r;
$p=imagecolorat($im,$x+$px,$y+$py);
imagesetpixel($img,$x,$y,$p);
}
}
header("Content-type: image/png");
imagepng($img);
imagedestroy($im);
imagedestroy($img);
?>

Bye.
Jasen

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация