/* * 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.text.math; import com.octo.captcha.text.TextCaptcha; /** * <p>Simple math captcha</p> * * @author <a href="mailto:marc.antoine.garrigue@gmail.com">Marc-Antoine Garrigue</a> * @version 1.0 */ public class MathCaptcha extends TextCaptcha { private String response; MathCaptcha(String question, String challenge, String response) { super(question, challenge); this.response = response; } /** * 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 Boolean.valueOf(response.equals(this.response)); } }