/    Sign up×
Community /Pin to ProfileBookmark

Graphic password/code script?

I have been to some sites where you have to type in a code or password that appears as a graphic. I believe it is done to prevent SPAM or attacks to the site.

How can I add this to my site? [B]is there a script that creates these graphical passwords?[/B]

thanks for any help ?

to post a comment
Full-stack Developer

17 Comments(s)

Copy linkTweet thisAlerts:
@JPnycSep 09.2005 — Scripts can't generate images. Those are images you're seeing. You have to create those yourself. The script can bring them up at random, but it can't make them
Copy linkTweet thisAlerts:
@HEADSTRONGauthorSep 09.2005 — Thanks for the quick reply

can you direct me in the right direction on how I can find the script or maybe purchase it? I assume the script also has to somehow authenicate or check the entered password with the graphical displayed password.

thanks again
Copy linkTweet thisAlerts:
@bathurst_guySep 09.2005 — Scripts can't generate images. Those are images you're seeing. You have to create those yourself. The script can bring them up at random, but it can't make them[/QUOTE]
php can do it, but i cant remember how atm, there was a post on this a little while ago
Copy linkTweet thisAlerts:
@JPnycSep 09.2005 — Finding one, I dunno. I would try all the major search engines. I've never written one of these but I have a good idea how it would be done. In fact it could be done clientside with Javascript. You'd place all the image file names into an array and use randomImageFile=Math.floor(Math.random()*totalNumberOfImagesHere) to pull them at random.

You'd need to create the image files 1st, then I would name the files the same as the contained password. Example: if the image shows 4RTMJ, name that pic file 4RTMJ.gif (or jpg, whatever). Then all you'd have to do is compare the contents of the text field with the file name held in your array index (the one that came up that time), and strip off the suffix.
Copy linkTweet thisAlerts:
@bathurst_guySep 09.2005 — talked about here by bokeh http://www.webdeveloper.com/forum/showthread.php?t=77412

CAPCHA verification ?
Copy linkTweet thisAlerts:
@bokehSep 09.2005 — Bathurst pointed me here. It is called capcha verification. Do a search on google. PHP can create the images without a problem. Go and read up first and see if it is for you though. Also consider how this effects blind people. For them you should offer an audio version of the image.
Copy linkTweet thisAlerts:
@HEADSTRONGauthorSep 09.2005 — Thanks everybody, for your help!

I prefer to do it in Javascript or ASP/vbscript if possible, I don't know PHP

But at least I know that it's called CAPCHA verification.

I will google some more

You guys rock!

thanks again
Copy linkTweet thisAlerts:
@bokehSep 09.2005 — If you do it client side (javascript) it is easy to bypass. I am going to write a script now to do this. I need time to think about it though.
Copy linkTweet thisAlerts:
@HEADSTRONGauthorSep 09.2005 — Great. thanks!
Copy linkTweet thisAlerts:
@ray326Sep 09.2005 — This has been done with Perl in the past using the Perl gd library or with an interface to the GIMP API.
Copy linkTweet thisAlerts:
@bokehSep 09.2005 — This has been done with Perl in the past using the Perl gd library or with an interface to the GIMP API.[/QUOTE]Sometimes it's writing it that is the challenge!

[B]Edited to simplify the code[/B]
[code=php]<?php
session_start();

function rand_string($len = 10){
$e = base64_encode(pack("h*", sha1(mt_rand())));
return substr(strtr($e, "+/=", "xyz"), 0, $len);
}

function capcha_image(){
header ('Content-type: image/jpeg');
$image = @imagecreate(110, 24);
$background = imagecolorallocate($image, 130,130,130);
$text_colour = imagecolorallocate($image, 90, 90, 90);
imagestring($image, 5, 9, 4, $_SESSION['capcha'], $text_colour);
imagejpeg($image, null, 100);
imagedestroy($image);
exit;
}

if(isset($_GET['image'])){ //create the image
if(empty($_SESSION['capcha']))exit;
capcha_image();
}else{ // html section
print '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">'."n".
'<html>'."n".
'<head>'."n".
'<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />'."n".
'<title>Capcha demo</title>'."n".
'</head>'."n".
'<body>'."n".
'<div style="margin-left: 50px;">'."n".
'<h2>Capcha demo</h2>'."n";
if(isset($_POST['submit'])){
if($_POST['capcha'] == $_SESSION['capcha']){
print '<p>Success! <br>You entered the correct code! <br>Here's another one to try!</p>';
}else{
print '<p>Failure! <br>You entered the wrong code! <br>Here's another one to try!</p>';
}
}
$_SESSION['capcha'] = rand_string();
print '<img style="border: 1px solid #555;" src="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].
'?image" width="110" height="24" alt="capcha image">'."n".
'<form style="margin-top: 0; action="http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'" method="post">'."n".
'<input type="text" name="capcha" style="width: 112px; margin-top: 5px; border: 1px solid #555; text-align: center;">'."n".
'<span style="color: red;"> *</span><br>'."n".
'<input type="submit" name="submit" value="try me" style="width: 112px; margin-top: 5px;">'."n".
'</form>'."n".
'<br><span style="color: red;">*</span> <i>case sensitive</i></div>'."n".
'</body>'."n".
'</html>';
}
?>[/code]
Copy linkTweet thisAlerts:
@HEADSTRONGauthorSep 09.2005 — anyway to do it in Javascript or VBscript/ASP?

Sorry, I don't know PHP

Thanks
Copy linkTweet thisAlerts:
@JPnycSep 09.2005 — You don't have to know it, he wrote it for you. All you need to know is if your host supports PHP. If it does, just call the script file onclick like any other file.
Copy linkTweet thisAlerts:
@bokehSep 09.2005 — If you didn't want a PHP solution why did you ask your question in the PHP forum? Well maybe someone else will find this working solution of some use. By th way once you've written your ASP solution would you come back and post it here as I would be interested to see it.
Copy linkTweet thisAlerts:
@bokehSep 09.2005 — Why has this script been kidnapped from the PHP forum? It is a PHP question and the solution will be wasted if it is not left in the PHP forum.
Copy linkTweet thisAlerts:
@HEADSTRONGauthorSep 10.2005 — what happend?
Copy linkTweet thisAlerts:
@HEADSTRONGauthorSep 10.2005 — HI All

Sorry I thought I was in the general forum...

anyways I found some code in ASP.NET for anyone interested.

Go to planetSourceCode.com and search for "Image verification" under .NET

I have not used it yet, but all the code is there.

Thanks for all your help
×

Success!

Help @HEADSTRONG spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...