Package com.andrewtimberlake.captcha

Examples of com.andrewtimberlake.captcha.Captcha


public class CaptchaImageGeneratorService extends HttpServlet {
  private static DateFormat RFC822_FORMAT = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");

  protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Captcha captcha = new Captcha();
    request.getSession().setAttribute("captcha", captcha);
    response.addHeader("Pragma", "No-cache");
    response.addHeader("Expires", RFC822_FORMAT.format(Calendar.getInstance().getTime()));
    String resource = request.getRequestURI();
    String extension = resource.substring(resource.lastIndexOf('.') + 1).toLowerCase();
    if (extension.equals("jpg") || extension.equals("png")) {
      BufferedImage image = captcha.generateImage();
      response.setContentType("image/" + extension);
      ImageIO.write(image, extension, response.getOutputStream());
    } else {
      BufferedImage image = captcha.generateImage();
      response.setContentType("image/png");
      ImageIO.write(image, "png", response.getOutputStream());
    }
  }
View Full Code Here


        // new account, it did NOT exist
        // validate captcha first
        if (StringUtils.isEmpty(captchaText)) {
          captchaText = "INVALID!";
        }
        Captcha captcha = (Captcha) getThreadLocalRequest().getSession().getAttribute("captcha");
        if (captcha != null && !captcha.isValid(captchaText)) {
          throw new SimpleMessageException("CAPTCHA validation failed");
        }

        User newUser = new User();
        newUser.setUsername(inUser.getUsername().toLowerCase());
View Full Code Here

TOP

Related Classes of com.andrewtimberlake.captcha.Captcha

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.