473,405 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

using PIL for anti-automation in ASP

I'm trying to create an anti-automation feature to prevent scripts
from running reports on our website by requiring users to enter a code
from an image (like Yahoo e-mail sign-up, or Network Solutions WHOIS
search).

I'm using Python as the scripting language in the ASP page, and using
PIL to generate the image. The code is stored into a session variable,
which is used to check the user's entry. It works fine the first time
around, but the problem I'm running into is that the page doesn't
refresh properly if the user returns to it. It just returns a blank
page.

Any help would be greatly appreciated. See code below:

<%@ LANGUAGE=Python%>
<html>
<head>
<title>Python ASP Page</title>
<%

import random
import PIL
import Image, ImageDraw, ImageFont

def password(n):

"""Returns a pseudo-random number of length n."""

# initialize empty string
s = ""

# generate random number, convert to string and append to s
for x in range(n):
i = random.randint(1,9)
s = s + str(i)

return s

def passwordImg(p):

"""Generates an image with text p."""

# open existing image
img = Image.open('C:\\Inetpub\\wwwroot\\BegASPFiles\\ima ges\\temppassword.gif')

# create new image
imgsize = (150,20) # image size
blue = (102,102,255) # image color
white = (255,255,255) # font color
newimg = Image.new("RGB",imgsize,blue)

# set font
arial = ImageFont.load('C:\\PythonScripts\\PILtest\\fonts\ \Arial
Bold_14_100.pil')

# create ImageDraw object to write text
draw = ImageDraw.Draw(newimg)
draw.text((40,-1),p, fill=white,font=arial)

# paste new image with password over old image
img.paste(newimg)

# save image and return true if successful
# Note: img.save returns None
imgPath = 'C:\\Inetpub\\wwwroot\\BegASPFiles\\images\\passwo rd.gif'
if img.save(imgPath):
return 0
else:
return 1
%>
</head>
<body>
<%

p = password(7)
Session.SetValue("key",p)
Response.Write("<p>")
//***********************
// check to see session variable has been written - remove for
production
//***********************
Response.Write(Session("key"))
Response.Write("</p>")

Response.Write("<p>test password:</p>")

if(passwordImg(p)):
Response.Write("<p><img src='images/password.gif' width='150'
height='20' alt='password'></p>")
else:
Response.Write("<p>Password image could not be generated.</p>")

Response.Write("<form action='pythonhandler.asp' method='POST'>")
Response.Write("<input type='text' name='pwd' size='10'><br>")
Response.Write("<input type='submit' value='Submit'>")
Response.Write("</form>")

%>
</p>
</body>
</html>
Jul 18 '05 #1
4 2427
Doug R wrote:
I'm trying to create an anti-automation feature to prevent scripts
from running reports on our website by requiring users to enter a code
from an image (like Yahoo e-mail sign-up, or Network Solutions WHOIS
search).

I'm using Python as the scripting language in the ASP page, and using
PIL to generate the image. The code is stored into a session variable,
which is used to check the user's entry. It works fine the first time
around, but the problem I'm running into is that the page doesn't
refresh properly if the user returns to it. It just returns a blank
page.


Maybe the users browser is caching the image/page? Try a unique image
name each time, or appending a date/time stamp to the image name
(image.gif?blah=12345). First, if you're using IE, you could also
disable page/image caching in the browser (you can do this in Mozilla
too I think, and other browsers).

Jay
Jul 18 '05 #2
do******@comcast.net (Doug R) writes:
I'm trying to create an anti-automation feature to prevent scripts
from running reports on our website by requiring users to enter a code
from an image (like Yahoo e-mail sign-up, or Network Solutions WHOIS
search).

[...]

It's called a captcha.

http://www.captcha.net/
You might like to note that the site above lists several programs that
can crack the kind of captcha you're talking about with around 80-90%
accuracy. So, if you've got determined attackers, you might prefer
one of the other schemes they suggest.
John
Jul 18 '05 #3
Thanks for the suggestions, and the reference site.

Doug
Jul 18 '05 #4
I see trouble here. What if two users tread on each other's password.gif ?
Use a unique filename (see module "tempfile" ) that should solve your
caching problem as well.

Best,
Miklós

--
PRISZNYÁK Miklós
---
Jegenye 2001 Bt. ( mailto:je*********@parkhosting.com )
Egyedi szoftverkészítés, tanácsadás
Custom software development, consulting
http://jegenye2001.parkhosting.com

Doug R <do******@comcast.net> wrote in message
news:52**************************@posting.google.c om...
I'm trying to create an anti-automation feature to prevent scripts
from running reports on our website by requiring users to enter a code
from an image (like Yahoo e-mail sign-up, or Network Solutions WHOIS
search).

[code deleted]
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: jcnews | last post by:
I am using Windows XP and am learning how to program in Java. Is there any way to get my fonts to be anti-aliased in both editors and in my programs? The non anti-aliased fonts don't look very...
0
by: Jason | last post by:
Hi guys, I am having problems with VML. I had been working on a problem for sometime now, and I just recently discovered what the problem really was: VML was anti-aliasing my rectangles, but I...
17
by: rgoya | last post by:
Peace be with you! About a year ago, I created a JavaScript which turns any web site into an online anti-war protest: http://www.geocities.com/rgoya/javascript/PROTEST.HTM I have recently...
3
by: Michel | last post by:
Is there a way I can anti-aliasing a gif to be able to get a hi-quality resizeable backgroundpicture. When a GIF of JPG is being resized by the browser you get wurse pictures because it needs a...
6
by: bissatch | last post by:
Hi, I want to display text on screen with anti aliasing to make it appear smoother. Is it possible to do this in browsers by perhaps applying a style to it or is it entirely up the the browser?...
22
by: Martin Eyles | last post by:
Hi, I have some text on a page in a small font. The font size has been OK in other applications, but in a web browser, the legebility suffers due to the anti-aliasing. Is there a way to turn off...
30
by: marc | last post by:
>From the book I am using as a reference I understood that applet tag was deprecated, but googling for information, and testing myself, it seems IE does not work properly with this new object tag....
3
by: =?Utf-8?B?TGlhbSBNYWM=?= | last post by:
Folks, Not sure if this is the correct forum for this posting, but I'm banging by head against the wall, I have been trying to use my WSH scripts in vb. net environment but not having much joy....
2
by: adam.timberlake | last post by:
I was following an article on a website earlier, and although it outputted the pie chart for me perfectly, I want to make it anti- aliased somehow. I have linked to the specific article below just...
20
by: cscorley | last post by:
For some reason, I cannot use fopen() on the file in write mode. The file "time" is in the same directory as the .php file, with permissions set to 0766. PHP Version 5.2.5 Apache/2.2.8 code...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.