Friday, September 15, 2006

Opera 9 browser on Ubuntu Dapper

I was pleased with Opera's offer for easy download and install of its browser for many linux platforms.
The installation was easy. Just double click on the .deb file and the installation will take care of the rest. Opera is famous for its lightweight and fast page loading. I find that it actually loads the web pages faster than any other browser. But there are some incompatibilities with lots of websites on the Internet for Opera browser. Even this blogger site textbox does not auto wrap the text to the next line.

Monday, September 11, 2006

Customizing JCAPTCHA, opensource Java api for CAPTCHA

It took me some time to customize the engine which generate words for CAPTCHA validation. The api has no easy way to change the behaviour of the word generation. After all, I find a way to do it. I extends the class SimpleListImageCaptchaEngine and overwrite buildInitialFactories method to get desired behaviour. Basically what I want is to use UPPERCASE letters and numbers only which are also safe from confusion(for example 0,O,L,I).Here's the code:

import java.awt.Color;

import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
import com.octo.captcha.component.image.backgroundgenerator.FunkyBackgroundGenerator;
import com.octo.captcha.component.image.fontgenerator.FontGenerator;
import com.octo.captcha.component.image.fontgenerator.TwistedAndShearedRandomFontGenerator;
import com.octo.captcha.component.image.textpaster.RandomTextPaster;
import com.octo.captcha.component.image.textpaster.TextPaster;
import com.octo.captcha.engine.image.gimpy.SimpleListImageCaptchaEngine;

public class MyImageCaptchaEngine extends SimpleListImageCaptchaEngine {

public MyImageCaptchaEngine() {
super();
}
protected void buildInitialFactories() {
com.octo.captcha.component.word.wordgenerator.WordGenerator wordGenerator = new com.octo.captcha.component.word.wordgenerator.RandomWordGenerator(
"123456789ABCDEFGHJKMNPQRSTUVWXYZ"); //Use only uppercase letters and safe characters (i.e. omits chars like O,L,I)
TextPaster textPaster = new RandomTextPaster(new Integer(5),
new Integer(8), Color.white);
BackgroundGenerator backgroundGenerator = new FunkyBackgroundGenerator(
new Integer(200), new Integer(100));
FontGenerator fontGenerator = new TwistedAndShearedRandomFontGenerator(
new Integer(25), new Integer(30));
com.octo.captcha.component.image.wordtoimage.WordToImage wordToImage = new com.octo.captcha.component.image.wordtoimage.ComposedWordToImage(
fontGenerator, backgroundGenerator, textPaster);
this.addFactory(
new com.octo.captcha.image.gimpy.GimpyFactory(wordGenerator,
wordToImage));
}
}