com.octo.captcha.image.gimpy.Gimpy Maven / Gradle / Ivy
The newest version!
/*
* JCaptcha, the open source java framework for captcha definition and integration
* Copyright (c) 2007 jcaptcha.net. All Rights Reserved.
* See the LICENSE.txt file distributed with this package.
*/
package com.octo.captcha.image.gimpy;
import com.octo.captcha.image.ImageCaptcha;
import java.awt.image.BufferedImage;
import java.io.Serializable;
/**
*
* A Gimpy is an ImageCaptcha. It is also the most common captcha.
*
*
* - Challenge type : image
* - Response type : String
* - Description : An image of a distorded word is shown. User have to
* recognize the word and to submit it.
*
*
* @author Marc-Antoine Garrigue
* @version 1.0
*/
public class Gimpy extends ImageCaptcha implements Serializable {
// private String response;
private boolean caseSensitive = true;
Gimpy(String question, BufferedImage challenge, String response, boolean caseSensitive) {
super(question, response, challenge);
this.caseSensitive = caseSensitive;
}
Gimpy(String question, BufferedImage challenge, String response) {
this(question, challenge, response, true);
}
/**
* Validation routine from the CAPTCHA interface. this methods verify if the
* response is not null and a String and then compares the given response to
* the internal string.
*
* @return true if the given response equals the internal response, false
* otherwise.
*/
public final Boolean validateResponse(final Object response) {
return (null != response && response instanceof String) ? validateResponse((String) response) : Boolean.FALSE;
}
/**
* Very simple validation routine that compares the given response to the
* internal string.
*
* @return true if the given response equals the internal response, false
* otherwise.
*/
private final Boolean validateResponse(final String response) {
return caseSensitive ? response.equals(this.response) : response.equalsIgnoreCase(this.response);
}
}