Jump to content

captcha test


SFB

Recommended Posts

I was wondering if anyone knew of a captcha test script. i need somewhere to start from. I suppose someone could write one up for me but I would rather have them spend their time on someone that needs the help more. so if someone could direct me to a good one, that would be great. thanks

Link to comment
Share on other sites

  • Replies 64
  • Created
  • Last Reply

Top Posters In This Topic

search the forum, or google it. I think that's the third request.
Ok fine, i will search myself. its just most of the time someone know one that works well and can pass it on. that way i dont have to sift through bad results. someone should teach me how to google. or mabey to be less specific. i never find what i want on a search engin. i end up making it myself :)edit: The reason i dont just search the forum is because i normally read through the majority of the php, css, html and general posts. i didnt rember one but i have missed some lately after the hacking because i have found more things to do during that time. anyways found this post http://w3schools.invisionzone.com/index.ph...&hl=captcha. i think this thread can be closed if anyone feels like closing it
Link to comment
Share on other sites

Whenever I'm looking for PHP help, my first search term is always php. Search for php captcha and see what you come up with. You can narrow it down more if you search for php captcha implementation, since that is specifically what you are looking for. You can search in Google groups to see what people are saying about them.

Link to comment
Share on other sites

If you're willing to build your own version, I think that you could actually do it fairly easily by using PHP's Image functions...just create a random string of text, output it as an image, and then ask them what the string is.
I was planning on making my own or customizing one but i always like to look at two or three good scrips first.
Link to comment
Share on other sites

<?phpfor ($i = 1; $i <= 6; $i++) {  // Create a random number between 1 and 3  $value = rand(1,3);  if($value == "1"){    //Generate a lower-case letter omitting l & add it to string    $char = chr(rand(97, 122));    $code .= $char;  }  if($value == "2"){    //Generate a number & add it to string    $char = rand(2, 9);    $code .= $char;  }  if($value == "3"){     //Generate a upper-case letter & add it to string     $char = chr(rand(65, 90));     $code .= $char;  }}echo"$code";?>

here is a script that i made that will generate a random number and letter code that has both upper and lower case letters. now all i have to do is everything else... i thought this was going to be the hard part but it wasnt so i'm happy about that. i'm off to learn how to use the gd library!ok now i have a working image... now got to play with it to make it more secure. then i will impliment my image into my message board!

<?phpfor ($i = 1; $i <= 6; $i++) {  // Create a random number between 1 and 3  $value = rand(1,3);  if($value == "1"){    //Generate a lower-case letter omitting l & add it to string    $char = chr(rand(97, 122));    $code .= $char;  }  if($value == "2"){    //Generate a number & add it to string    $char = rand(2, 9);    $code .= $char;  }  if($value == "3"){     //Generate a upper-case letter & add it to string     $char = chr(rand(65, 90));     $code .= $char;  }}$randomcode = str_split($code);// Create the image with width=150 and height=40$random_image = imagecreate(150,40);// Set some colors$black = imagecolorallocate ($random_image, 0, 0, 0);$white = imagecolorallocate ($random_image, 255, 255, 255);// backgroudn blackimagefill($random_image, 0, 0, $black);// write the 6 charictors in various fontsimagechar($random_image, 4, 20, 13, $randomcode[0] ,$white);imagechar($random_image, 5, 40, 13, $randomcode[1] ,$white);imagechar($random_image, 3, 60, 13, $randomcode[2] ,$white);imagechar($random_image, 4, 80, 13, $randomcode[3] ,$white);imagechar($random_image, 5, 100, 13, $randomcode[4] ,$white);imagechar($random_image, 3, 120, 13, $randomcode[5] ,$white);//Now we send the picture to the Browserheader("Content-type: image/jpeg");imagejpeg($random_image);?>

Link to comment
Share on other sites

If you're willing to build your own version, I think that you could actually do it fairly easily by using PHP's Image functions...just create a random string of text, output it as an image, and then ask them what the string is.
It's not that simple, a screen reader will be able to read that. To make a good captcha, you will want to distort the text so that the characters are wavy or otherwise distorted. It's also a good idea to use variable fonts, sizes, and colors for each character. It also helps make the captcha harder for a machine to read if the text is rotated an odd angle, like 17 degrees or 51 degrees. Something random. Not 45 degrees. Another thing is to offset each letter from each other, so instead of having them all in a line, have some above the line and some below it. And lastly, it helps to have a background with colors or even light text in the background to help throw off the machines.The whole point of a captcha is to defeat an OCR screen reader, so if you just have normal text in the image you're not really doing any good. The last part is sending the value of the text to the next page, it would be pointless to just send the string in a hidden input element because that could be read instead of the image. So you need to either send an encrypted version of the text that you can decrypt and test, or base the text in the image off some variables like the IP address and user agent, or some combination of static values that you can use to generate the same pseudorandom value on the other end. It might be a good idea to generate the string by taking an MD5 or SHA-1 hash of the user agent and host or something, and then using the IP address numbers to determine which position in the hash to get your substring from. That would let you generate the same value on the other end. But a single person would always see the same captcha, assuming that their IP address never changes. That wouldn't work for someone behind a proxy though, or someone on AOL, because the two requests would come from different IPs. So you probably need to figure a way to encrypt and decrypt the string to check it.Also, the code you have up there SFB claims to use different fonts, but it doesn't.
Link to comment
Share on other sites

thanks for the suggestions. i am making this one step at a time. currently i am working on the image. i got to figure out how to add a custom fonts but otherwise its going good. would it work to set the code in a session and then look at the session and if it matches then destroy the session so they cant use it again? it seems like that may be unsecure but i thought i would ask

Link to comment
Share on other sites

Nice captcha SFB, but the font thing isnt working. Is it possible to make the letters in bold and italics and such?
i dont know how to get different fonts. I thought 1-5 were different fonts but they seem to be just different sizes. I cant figure out how to rotate a letter eather. I will keep looking.
Link to comment
Share on other sites

This is all you need:http://www.php.net/manual/en/function.imagettftext.phpsize, angle, x, y, color, fontIt uses TrueType fonts, which are in .ttf files. You can probably find a bunch of them in your Windows font folder. For reliability, you might as well copy the ttf files you want to use into the same folder as the PHP script, and use this chunk of code from the imagettftext reference page to set the path:

<?php// Set the enviroment variable for GDputenv('GDFONTPATH=' . realpath('.'));// Name the font to be used (note the lack of the .ttf extension)$font = 'SomeFont';?>

Link to comment
Share on other sites

ok so i uploaded the fonts and named them font(1-10). then i went and did this(for ($i = 1; $i <= 6; $i++) { $font[$i] = "font".rand(1,10);}that way for each letter i can have a random choice of 10 fonts. for some reason i cant get all of my letters/numbers to show up at onece. i am 99% sure that all the fonts are .ttfi moved the location of the image to http://snowforts.ath.cx/captcha/image.phpedit: oops why did i originally write rand(75,85) i ment 1,10

Link to comment
Share on other sites

i got it working for the most part now. about 15% of the time i would guess, a letter/number overlaps more than i want it to. i am narrowed down the range of where the letters can be and how large/small they can be but i dont want to do that any more. i think i should add some space between them but i want them to overlap sometimes so it would be harder for a bot to figure outhow would i choose a random number but omit certin numbers?i could just replace the number but then certin numbers would occur more often.

Link to comment
Share on other sites

I would recommend using an array also. Since you have all the different fonts, I would also recommend not using 1, i, I, l, o, O, or 0. But, you can have the other 8 digits, and then both uppercase and lowercase letters minus the ones I said, and have it be case-sensitive. You can load all of them in an array, and you can actually use this one function to get 6 random entries from the array all at once:http://www.php.net/manual/en/function.array-rand.phpCheck the example on that page to see how it works.But other than that stuff, and maybe the addition of some colors, it's actually looking really good. It would be interesting to try and run some OCR on it, I think the success rate would be very low for the software. You might try this one:http://www.simpleocr.com/

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...