Showing posts with label captcha. Show all posts
Showing posts with label captcha. Show all posts

Wednesday, June 29, 2016

How to Code Your Own CAPTCHA Script In PHP

Today I will show you how to code your own CAPTCHA Script.
<?php
session_start();
$strlength = rand(4,7);

for($i=1;$i<=$strlength;$i++)
{
$textornumber = rand(1,3);
if($textornumber == 1)
{
$captchastr .= chr(rand(49,57));
}
if($textornumber == 2)
{
$captchastr .= chr(rand(65,78));
}
if($textornumber == 3)
{
$captchastr .= chr(rand(80,90));
}
}
$randcolR = rand(100,230);
$randcolG = rand(100,230);
$randcolB = rand(100,230);

/initialize image $captcha is handle dimensions 200,50
$captcha = imageCreate(200,50);
$backcolor = imageColorAllocate($captcha, $randcolR, $randcolG, $randcolB);

$txtcolor = imageColorAllocate($captcha, ($randcolR - 20), ($randcolG - 20), ($randcolB - 20));
for($i=1;$i<=$strlength;$i++)
{

$clockorcounter = rand(1,2);
if ($clockorcounter == 1)
{
$rotangle = rand(0,45);
}
if ($clockorcounter == 2)
{
$rotangle = rand(315,360);
}

//$i*25 spaces the characters 25 pixels apart
imagettftext($captcha,rand(14,20),$rotangle,($i*25),30,$txtcolor,"/arial.ttf",substr($captchastr,($i-1),1));
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$txtcolor);
}
for($i=1; $i<=4;$i++)
{
imageellipse($captcha,rand(1,200),rand(1,50),rand(50,100),rand(12,25),$backcolor);
}
//Send the headers (at last possible time)
header(Content-type: image/png);

//Output the image as a PNG
imagePNG($captcha);

//Delete the image from memory
imageDestroy($captcha);

$_SESSION[captchastr] = $captchastr;

?>
If you like this script then feel free to Subscribe to our blog and we will email you similar interesting and useful PHP scripts in your Inbox as soon as it is published on our blog.

Enjoy!


Sunday, June 12, 2016

DHTML and CSS CAPTCHA

CAPTCHA is the name of an approach used to distinguish site accesses performed by real humans from robot script accesses.

Usually the pages show fuzzy pictures with letters that the user needs to guess. However there are smart anti-CAPTCHA robots that can also guess what is written in CAPTCHA picture.

This package provides an alternative CAPTCHA solution that consists in using colored boxes that the user must click in order to have access to the protected site resources.

Since this is a new approach, it is harder to break by people that employ common anti-CAPTCHA scripts.

Name: DHTML and CSS CAPTCHA Support forum
Base name: as_snipercaptcha
Description: CAPTCHA validation using colored boxes and AJAX
Version: 1.03.007
Required PHP version: 4.3.0
License: GNU General Public License (GPL)

Detailed description
This class can be used to implement CAPTCHA validation using colored boxes that the user must click which are validated using AJAX requests.

It renders a grid of boxes on which only one box is colored differently to indicate the user must click it.

The class sends an AJAX request to the server passing the coordinates of the user clicks until a given number of clicks correctly point to the colored boxes.

Download here

Sunday, June 5, 2016

PHP CAPTCHA Script A Simple But Effective Free CAPTCHA Script in PHP

PhpCaptcha php script is a library for generating visual and audio CAPTCHAs (completely automated public Turing test to tell computers and humans apart). You can read more about CAPTCHAs at Wikipedia.

It can help you to prevent/reduce:

  •     Automated sign-ups in registration forms.
  •     Comment spam in blogs and guestbooks.
  •     Brute force attacks on login systems.


A Word of Warning

OK, so this might sounds strange given what follows but please consider whether you really need to use a CAPTCHA before implementing this on your site. Although its legitimate to use CAPTCHAs in some situations you really need to be aware of the inherent accessibility pitfalls before implementing. Id also encourage you to fully investigate the alternatives such as the Akismet spam filtering WordPress plug-in and API before resorting to a CAPTCHA to solve your spam problems.

Right, Ive said my piece - on with the script.

Origins

The library is loosely based on an article I wrote for SitePoint which was published on 9th November 2005 - Toughen Forms Security with an Image.

Supported Features

  •     Multiple random TrueType fonts
  •     Character rotation
  •     Optional chararacter shadow support
  •     Optional site owner display text
  •     Random custom background images
  •     Font size selection
  •     Greyscale or colour lines and characters
  •     Character set selection
  •     Integration of validation function for checking the user entered code with the generated code

Requirements

The library requires PHP 4 compiled with GD 1 or 2 (Image Generation) and FreeType text support. It should work fine with Linux, Mac OS X or Windows based systems although you will need to change the default temporary file storage directory specified when using with Windows. PHP session support is also required. The audio CAPTCHA requires the Flite text to speech synthesis engine - more details on set up below.

License

PhpCaptcha is licensed under the Free BSD license.

Implementation Steps:

Step 1

Unzip and copy the php-captcha.inc.php to a directory within your site.

Step 2

To create a basic visual CAPTCHA with the minimal options create a new file (visual-captcha.php) containing the code shown below.


 <?php
require(php-captcha.inc.php);
$aFonts = array(fonts/VeraBd.ttf, fonts/VeraIt.ttf, fonts/Vera.ttf);
$oVisualCaptcha = new PhpCaptcha($aFonts, 200, 60);
$oVisualCaptcha->Create();
?>

Step 3

To create an audio CAPTCHA create a new file (audio-captcha.php) containing the code shown below. For this to work youll need to ensure that your have a working installation of Flite.
 <?php
require(php-captcha.inc.php);
$oAudioCaptcha = new AudioPhpCaptcha(/usr/bin/flite, /tmp/);
$oAudioCaptcha->Create();
?>

You need to pass the path to the Flite binary and the temporary directory you want to use for storing generated audio CAPTCHAs to the class constructor. Alternatively you can modify the corresponding constants in the library file and then omit the parameters in the constructor.

Step 4

Include the visual and audio CAPTCHAs in your application/form with the following code. The audio CAPTCHA should ideally follow the visual CAPTCHA in the source code. This will ensure the visual CAPTCHA has generated a random code before the audio CAPTCHA is called.


 <p><img src="visual-captcha.php" width="200" height="60" alt="Visual CAPTCHA" /></p>
<p><a href="audio-captcha.php">Cant see the image? Click for audible version</a></p>

Step 5

On form submission you need to check the code the user enters with the one generated by the CAPTCHA. You can do this with the following code assuming that the user entered code was submitted in an HTML POST form field "user_code".


 <?php
require(php-captcha.inc.php);
if (PhpCaptcha::Validate($_POST[user_code])) {
echo Valid code entered;
} else {
echo Invalid code entered;
}
?>

Please note that the Validate method needs to be called statically, i.e you dont create an instance of the class before calling it.

Configuration Options

  1. SetWidth(int iWidth) - set the width of the CAPTCHA image. Defaults to 200px.
  2. SetHeight(int iHeight) - set the height of the CAPTCHA image. Defaults to 50px.
  3. SetNumChars(int iNumChars) - set the number of characters to display. Defaults to 5.
  4. SetNumLines(int iNumLines) - set the number of interference lines to draw. Defaults to 70.
  5. DisplayShadow(bool bShadow) - specify whether or not to display character shadows.
  6. SetOwnerText(sting sOwnerText) - owner text to display at bottom of CAPTCHA image, discourages attempts to break your CAPTCHA through display on porn and other unsavoury sites.
  7. SetCharSet(variant vCharSet) - specify the character set to select characters from. If left blank defaults to A-Z. Can be specified as an array of chracters e.g. array(1, G, 3) or as a string of characters and character ranges e.g. a-z,A-Z,0,3,7.
  8. CaseInsensitive(bool bCaseInsensitive) - specify whether or not to save user code preserving case. If setting to "false" you need to pass "false" as the second parameter to the "Validate" function when checking the user entered code.
  9. SetBackgroundImages(variant vBackgroundImages) - specify one (a string) or more (an array) images to display instead of noise lines. If more than one image is specified the library selects one at random.
  10. SetMinFontSize(int iMinFontSize) - specify the minimum font size to display. Defaults to 16.
  11. SetMaxFontSize(int iMaxFontSize) - specify the maximum font size to display. Defaults to 25.
  12. UseColour(bool bUseColour) - if true displays noise lines and characters in randomly selected colours.
  13. SetFileType(string sFileType) - specify the output format jpeg, gif or png. Defaults to jpeg.
The methods listed below allow you to refine the look and feel as well as the behaviour of the generated CAPTCHA. They should all be called before the "Create" method.

Download Free PHP CAPTCHA Script

Thursday, June 2, 2016

Free Image Verification Captcha Script In PHP

DRBImageVerification is a simple anti-spam image verification, or CAPTCHA, script. It allows you to add a challenge-response test to your existing PHP powered forms to prevent automated spam postings.

Features

  • Quick and easy to install.
  • Verification string length and character list are configurable.
  • Requires a session cookie, for additional obscurity.
  • Includes an example PHP page demonstrating how to add a verification image to a form.

Download Image Verification Script

Sunday, May 29, 2016

Friendly Captcha

This package can be used to implement CAPTCHA validation using text with math expression.

There is a base class that can display a text message to tell the user what he needs to input.

A math subclass generates an expression with a random math operation between two number values.

The user must enter the result of the operation to pass the CAPTCHA validation. The correct answer is stored in session variables for posterior validation.

All files are written by Chris Hepner.

You can download it here (19kb)