navigator Guest
|
Posted: Thu Oct 27, 2005 11:11 am Post subject: Updated code to use MD5! |
|
|
My host had removed SHA, which was deprecated (replaced) due to security concerns. This caused Antibot to stop working, but I have finally figured out how to get it to use MD5. The changes are below. My code is based on perlreply.cgi.
In png.py, make these changes near the top of the file...
old:
import sys
import os, sha
import struct
new:
import sys
import os, md5
import struct
And near the end of the file...
old:
s = sha.new(seqstr)
image=encodePNG(ImagePath+'/test'+s.hexdigest()+'.png',NumberOfChars*WidthOfChars+comb.extrawidth,HeightOfChars+12)
image.IDAT = comb.filedata
image.create()
image.close()
h = createHtml(s.hexdigest())
new:
s = md5.new(seqstr)
image=encodePNG(ImagePath+'/test'+s.hexdigest()+'.png',NumberOfChars*WidthOfChars+comb.extrawidth,HeightOfChars+12)
image.IDAT = comb.filedata
image.create()
image.close()
h = createHtml(s.hexdigest())
For perlreply.cgi, I included the code as a subroutine in another file. I have posted the sub here; it may help others incorporate Antibot into their code.
old (partial):
$seq = $q->param("sequence");
$realseq = $q->param("realsequence");
$context = new SHA;
$context->reset();
$seq = $context->hexhash($seq);
new:
sub addit {
#------------------------------------------
# This makes sure the security code they entered is correct.
use Digest::MD5;
if ($in{'sequence'}) {
$seq = ($in{'sequence'});
$realseq = ($in{'realsequence'});
$context = Digest::MD5->new;
$context->add($seq);
$seq = $context->hexdigest;
if ($realseq eq $seq) {
&process_form;
}
else {
&site_html_add_failure("You entered the wrong security code.") and return;
}
}
else {
&site_html_add_failure("You did not enter the security code.") and return;
}
} #end sub addit
Hope this helps others use Antibot, which is a great way to stop spammers! |
|