Class CaptchaHelper

java.lang.Object
org.ametys.core.captcha.CaptchaHelper
All Implemented Interfaces:
Serviceable

public final class CaptchaHelper extends Object implements Serviceable
Helper for generating image captcha to PNG format
  • Constructor Details

  • Method Details

    • service

      public void service(ServiceManager manager) throws ServiceException
      Specified by:
      service in interface Serviceable
      Throws:
      ServiceException
    • getCaptchaType

      public static String getCaptchaType()
      Retrieve the type of captcha used
      Returns:
      The type of captcha.
    • checkAndInvalidate

      public static boolean checkAndInvalidate(String key, String value)
      Check a captcha
      Parameters:
      key - The captcha key. Can be empty or null when using reCaptcha.
      value - The value to check
      Returns:
      true if the captcha is valid, false otherwise.
    • checkAndInvalidateJCaptcha

      public static boolean checkAndInvalidateJCaptcha(String key, String value)
      Check a captcha
      Parameters:
      key - The key
      value - The value to check
      Returns:
      The image captcha
    • checkAndInvalidateReCaptcha

      public static boolean checkAndInvalidateReCaptcha(String value)
      Check a ReCaptcha value
      Parameters:
      value - The value to check
      Returns:
      True if the captcha is valid.
    • removeCaptcha

      public static void removeCaptcha(String key)
      Remove a captcha
      Parameters:
      key - the key value
    • cleanOldCaptchas

      public static void cleanOldCaptchas()
      Clean the outdated captchas
    • generateImageCaptcha

      Generate an image captcha to PNG format. The key has to be unique. If you can not give a unique id use generateImageCaptch without the key argument : but this is less secure.
      Parameters:
      key - the wanted key. Can be not null. MUST START with "STATIC-" or "DYNAMIC-". If the key starts with 'STATIC-' this key may be used several times (e.g. for a cached page with a unique id for several display), if the key starts with 'DYNAMIC-' the key will unique (removing an existing captcha with the same key).
      Returns:
      The corresponding image
    • generateImageCaptcha

      public static BufferedImage generateImageCaptcha(String key, boolean addNoise, boolean fisheye)
      Generate an image captcha to PNG format. The key has to be unique. If you can not give a unique id use generateImageCaptch without the key argument : but this is less secure.
      Parameters:
      key - the wanted key. Can be not null. MUST START with "STATIC-" or "DYNAMIC-". If the key starts with 'STATIC-' this key may be used several times (e.g. for a cached page with a unique id for several display), if the key starts with 'DYNAMIC-' the key will unique (removing an existing captcha with the same key).
      addNoise - true to add noise to captcha image
      fisheye - true to add fish eye background to captcha image
      Returns:
      The corresponding image
    • generateImageCaptcha

      public static BufferedImage generateImageCaptcha(String key, Integer color)
      Generate an image captcha to PNG format. The key has to be unique, if you cannot generate a key use the other form of the method.
      Parameters:
      key - the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates one
      color - The color for font
      Returns:
      The corresponding image
    • generateImageCaptcha

      public static BufferedImage generateImageCaptcha(String key, Integer color, boolean addNoise, boolean fisheye)
      Generate an image captcha to PNG format. The key has to be unique, if you cannot generate a key use the other form of the method.
      Parameters:
      key - the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates one
      color - The color for font
      addNoise - true to add noise to captcha image
      fisheye - true to add fish eye background to captcha image
      Returns:
      The corresponding image
    • generateImageCaptcha

      public static BufferedImage generateImageCaptcha(String key, Integer color, boolean addNoise, boolean fisheye, int width, int height)
      Generate an image captcha to PNG format. The key has to be unique, if you cannot generate a key use the other form of the method.
      Parameters:
      key - the wanted key. Can not be null. You can use RandomStringUtils.randomAlphanumeric(10) to generates one
      color - The color for font
      addNoise - true to add noise to captcha image
      fisheye - true to add fish eye background to captcha image
      width - The image width
      height - The image height
      Returns:
      The corresponding image