View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   package com.octo.captcha.text.math;
8   
9   import com.octo.captcha.text.TextCaptcha;
10  
11  /***
12   * <p>Simple math captcha</p>
13   *
14   * @author <a href="mailto:marc.antoine.garrigue@gmail.com">Marc-Antoine Garrigue</a>
15   * @version 1.0
16   */
17  public class MathCaptcha extends TextCaptcha {
18  
19  	private String response;
20  
21      MathCaptcha(String question, String challenge, String response) {
22          super(question, challenge);
23          this.response = response;
24      }
25  
26      /***
27       * Validation routine from the CAPTCHA interface. this methods verify if the response is not null and a String and
28       * then compares the given response to the internal string.
29       *
30       * @return true if the given response equals the internal response, false otherwise.
31       */
32      public final Boolean validateResponse(final Object response) {
33          return (null != response && response instanceof String)
34                  ? validateResponse((String) response) : Boolean.FALSE;
35      }
36  
37      /***
38       * Very simple validation routine that compares the given response to the internal string.
39       *
40       * @return true if the given response equals the internal response, false otherwise.
41       */
42      private final Boolean validateResponse(final String response) {
43          return Boolean.valueOf(response.equals(this.response));
44      }
45  }