当前位置: 首页>>代码示例>>Java>>正文


Java Captcha类代码示例

本文整理汇总了Java中nl.captcha.Captcha的典型用法代码示例。如果您正苦于以下问题:Java Captcha类的具体用法?Java Captcha怎么用?Java Captcha使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Captcha类属于nl.captcha包,在下文中一共展示了Captcha类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCaptchaImage

import nl.captcha.Captcha; //导入依赖的package包/类
private void getCaptchaImage(HttpServletRequest request, HttpServletResponse response) throws IOException
{
	String seed = request.getParameter("seed");
	if (seed == null || seed.isEmpty())
	{
		response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
		return;
	}
	int seed_;
	try
	{
		seed_ = Integer.parseInt(seed);
	}
	catch (NumberFormatException i)
	{
		response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE);
		return;
	}
	PredictableCaptchaTextProducer producer = new PredictableCaptchaTextProducer(seed_);
	final Captcha captcha = new Captcha.Builder(160, 50).addText(producer).addBackground(new GradiatedBackgroundProducer()).addNoise().gimp(new FishEyeGimpyRenderer()).addBorder().build();
	CaptchaServletUtil.writeImage(response, captcha.getImage());
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:23,代码来源:WebServlet.java

示例2: doGet

import nl.captcha.Captcha; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		
		List<java.awt.Font> textFonts = Arrays.asList(
		     new Font("Arial", Font.BOLD, 40), 
		     new Font("Courier", Font.BOLD, 40));
	    Captcha captcha = new Captcha.Builder(250, 90).addText()
			.addBackground(new FlatColorBackgroundProducer(Color.YELLOW))
			.gimp(new FishEyeGimpyRenderer())
			.addNoise(new CurvedLineNoiseProducer())
			.addText(new DefaultTextProducer(5), 
					 new DefaultWordRenderer(Color.RED, textFonts))
			.build();

	    CaptchaServletUtil.writeImage(resp, captcha.getImage());
	    req.getSession().setAttribute(NAME, captcha);
}
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:19,代码来源:SimpleCaptchaCustomServlet.java

示例3: testShouldExpire

import nl.captcha.Captcha; //导入依赖的package包/类
@Test
public void testShouldExpire() {
    Captcha captcha = new Captcha.Builder(200, 50)
        .addText()
        .build();
    
    assertFalse(StickyCaptchaServlet.shouldExpire(captcha));
    
    StickyCaptchaServlet.setTtl(0);
    assertTrue(StickyCaptchaServlet.shouldExpire(captcha));
    
    assertEquals(0, StickyCaptchaServlet.getTtl());
    StickyCaptchaServlet.setTtl(-1000);
    assertEquals(0, StickyCaptchaServlet.getTtl());
    
    StickyCaptchaServlet.setTtl(Long.MAX_VALUE);
    assertFalse(StickyCaptchaServlet.shouldExpire(captcha));
}
 
开发者ID:rookiefly,项目名称:simplecaptcha,代码行数:19,代码来源:StickyCaptchaServletTest.java

示例4: isValid

import nl.captcha.Captcha; //导入依赖的package包/类
public boolean isValid(HttpSession session) {
  Captcha captchaValue = (Captcha) session.getAttribute(Captcha.NAME);
  session.removeAttribute(Captcha.NAME);
  if (captchaValue == null || captcha == null ||
      !captchaValue.isCorrect(captcha)) {
    errors.put("captchaError", "Text did not match image");
  }
  if (!StringUtils.hasText(getNameFirst())) {
    errors.put("nameFirstError", "Required field");
  }
  if (!StringUtils.hasText(getNameLast())) {
    errors.put("nameLastError", "Required field");
  }
  if (!StringUtils.hasText(getEmail())) {
    errors.put("emailError", "Required field");
  }
  if (!StringUtils.hasText(getDescription())) {
    errors.put("descriptionError", "Required field");
  }
  return (!hasErrors());
}
 
开发者ID:Concursive,项目名称:concourseconnect-community,代码行数:22,代码来源:ContactUsBean.java

示例5: doGet

import nl.captcha.Captcha; //导入依赖的package包/类
@Override
public void doGet(final HttpServletRequest req, final HttpServletResponse resp)
    throws ServletException,
    IOException {
    final HttpSession session = req.getSession();

    final Captcha captcha = new Captcha.Builder(_width, _height)
        .addText()
        .addBackground(new GradiatedBackgroundProducer())
        .gimp()
        .addBackground(new FlatColorBackgroundProducer(new Color(238, 238, 238)))
        .addBorder()
        .addNoise()
        .build();

    session.setAttribute(NAME, captcha);

    CaptchaServletUtil.writeImage(resp, captcha.getImage());
}
 
开发者ID:inepex,项目名称:ineform,代码行数:20,代码来源:CaptchaServlet.java

示例6: updateCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
@At("/captcha/update")
	@Ok("raw:image/png")
	public BufferedImage updateCaptcha(HttpSession session, @Param("w") int w, @Param("h") int h) {
		if (w * h == 0) { //长或宽为0?重置为默认长宽.
			w = 200;
			h = 60;
		}
		Captcha captcha = new Captcha.Builder(w, h)
								.addText().addBackground(new GradiatedBackgroundProducer())
//								.addNoise(new StraightLineNoiseProducer()).addBorder()
								.gimp(new FishEyeGimpyRenderer())
								.build();
		String text = captcha.getAnswer();
		session.setAttribute(Toolkit.captcha_attr, text);
		return captcha.getImage();
	}
 
开发者ID:amdiaosi,项目名称:nutzWx,代码行数:17,代码来源:ToolkitModule.java

示例7: doGet

import nl.captcha.Captcha; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    //ColoredEdgesWordRenderer wordRenderer = new ColoredEdgesWordRenderer(COLORS, FONTS);
    ColoredEdgesWordRenderer wordRenderer = new ColoredEdgesWordRenderer(COLORS, FONTS, 1f);
    Captcha captcha = new Captcha.Builder(_width, _height).addText(wordRenderer)
            //.gimp()
            .addNoise()
            //.addBackground(new GradiatedBackgroundProducer())
            //.addBackground(new TransparentBackgroundProducer())
            //.addBackground(new FlatColorBackgroundProducer(Color.lightGray))
            .addBackground(new GradiatedBackgroundProducer(Color.lightGray, Color.white))
            .build();

    CaptchaServletUtil.writeImage(resp, captcha.getImage());
    req.getSession().setAttribute(NAME, captcha);
}
 
开发者ID:NCIP,项目名称:nci-metathesaurus-browser,代码行数:18,代码来源:NCISimpleCaptchaServlet.java

示例8: validateSimpleCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
public static boolean validateSimpleCaptcha( HttpSession session, String answer) {
    Captcha captcha = (Captcha) session.getAttribute( Captcha.NAME );
    String code = captcha.getAnswer();
    if( code.equals(answer) ) {
        return true;
    }
    return false;
}
 
开发者ID:PacktPublishing,项目名称:Spring-MVC-Blueprints,代码行数:9,代码来源:FeedbackFormController.java

示例9: doGet

import nl.captcha.Captcha; //导入依赖的package包/类
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    ColoredEdgesWordRenderer wordRenderer = new ColoredEdgesWordRenderer(COLORS, FONTS);
    Captcha captcha = new Captcha.Builder(_width, _height).addText(wordRenderer)
            .gimp()
            .addNoise()
            .addBackground(new GradiatedBackgroundProducer())
            .build();

    CaptchaServletUtil.writeImage(resp, captcha.getImage());
    req.getSession().setAttribute(NAME, captcha);
}
 
开发者ID:rookiefly,项目名称:simplecaptcha,代码行数:14,代码来源:SimpleCaptchaServlet.java

示例10: buildAndSetCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
private Captcha buildAndSetCaptcha(HttpSession session) {
    Captcha captcha = new Captcha.Builder(_width, _height)
        .addText()
        .gimp()
        .addBorder()
        .addNoise()
        .addBackground()
        .build();

    session.setAttribute(NAME, captcha);
    return captcha;
}
 
开发者ID:rookiefly,项目名称:simplecaptcha,代码行数:13,代码来源:StickyCaptchaServlet.java

示例11: shouldExpire

import nl.captcha.Captcha; //导入依赖的package包/类
static boolean shouldExpire(Captcha captcha) {
    long ts = captcha.getTimeStamp().getTime();
    long now = new Date().getTime();
    long diff = now - ts;

    return diff >= _ttl;
}
 
开发者ID:rookiefly,项目名称:simplecaptcha,代码行数:8,代码来源:StickyCaptchaServlet.java

示例12: isValid

import nl.captcha.Captcha; //导入依赖的package包/类
/**
 * Gets the valid attribute of the UserBean object
 *
 * @param session the browser sessions
 * @return The valid value
 */
public boolean isValid(HttpSession session) {
  Captcha captchaValue = (Captcha) session.getAttribute(Captcha.NAME);
  session.removeAttribute(Captcha.NAME);
  if (captchaValue == null || captcha == null ||
      !captchaValue.isCorrect(captcha)) {
    errors.put("captchaError", "Text did not match image");
  }
  if (!StringUtils.hasText(nameFirst)) {
    errors.put("nameFirstError", "Required field");
  }
  if (!StringUtils.hasText(nameLast)) {
    errors.put("nameLastError", "Required field");
  }
  if (!StringUtils.hasText(companyName)) {
    errors.put("companyNameError", "Required field");
  }
  if (!StringUtils.hasText(email)) {
    errors.put("emailError", "Required field");
  }
  if (!StringUtils.hasText(phone)) {
    errors.put("phoneError", "Required field");
  }
  if (!StringUtils.hasText(addressLine1)) {
    errors.put("addressLine1Error", "Required field");
  }
  if (!StringUtils.hasText(getCity())) {
    errors.put("cityError", "Required field");
  }
  if (getState() == null || getState().equals("-1")) {
    errors.put("stateError", "Required field");
  }
  if (getCountry() == null || getCountry().equals("-1")) {
    errors.put("countryError", "Required field");
  }
  if (!agreement) {
    errors.put("agreementError", "Accepting the terms and conditions is required");
  }
  return (!hasErrors());
}
 
开发者ID:Concursive,项目名称:concourseconnect-community,代码行数:46,代码来源:DemoBean.java

示例13: validateCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
private String validateCaptcha(HttpServletRequest request,
      String returnIncompleteState) throws Exception {
      Captcha captcha = (Captcha) request.getSession().getAttribute(Captcha.NAME);
      if (captcha == null) {
          captcha = new Captcha.Builder(200, 50).addText().addBackground()
              // .addNoise()
              .gimp()
              // .addBorder()
              .build();
          request.getSession().setAttribute(Captcha.NAME, captcha);
      }

      // Do this so we can capture non-Latin chars
      request.setCharacterEncoding("UTF-8");
      String answer = HTTPUtils.cleanXSS((String) request.getParameter("answer"));
      if (answer == null || answer.length() == 0) {
          throw new NoReloadException(
              "Please enter the characters appearing in the image. ");
      }

      request.getSession().removeAttribute("reload");
      if (!captcha.isCorrect(answer)) {
          throw new InvalidCaptChaInputException(
              "WARNING: The string you entered does not match"
                  + " with what is shown in the image. Please try again.");
}
request.getSession().removeAttribute(Captcha.NAME);
      return null;
  }
 
开发者ID:NCIP,项目名称:nci-metathesaurus-browser,代码行数:30,代码来源:UserSessionBean.java

示例14: validateCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
private String validateCaptcha(HttpServletRequest request,
      String returnIncompleteState) throws Exception {
      Captcha captcha = (Captcha) request.getSession().getAttribute(Captcha.NAME);
      if (captcha == null) {
          captcha = new Captcha.Builder(200, 50).addText().addBackground()
              // .addNoise()
              .gimp()
              // .addBorder()
              .build();
          request.getSession().setAttribute(Captcha.NAME, captcha);
      }

      // Do this so we can capture non-Latin chars
      request.setCharacterEncoding("UTF-8");
      String answer = HTTPUtils.cleanXSS((String) request.getParameter("answer"));
      if (answer == null || answer.length() == 0) {
          throw new NoReloadException(
              "Please enter the characters appearing in the image. ");
      }

      request.getSession().removeAttribute("reload");
      if (!captcha.isCorrect(answer)) {
          throw new InvalidCaptChaInputException(
              "WARNING: The string you entered does not match"
                  + " with what is shown in the image. Please try again.");
} else {
}        request.getSession().removeAttribute(Captcha.NAME);
      return null;
  }
 
开发者ID:NCIP,项目名称:nci-term-browser,代码行数:30,代码来源:UserSessionBean.java

示例15: createCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
/**
 * Creates a {@link Captcha} and stores it in the session.
 *
 * @param width  the width of the image
 * @param height the height of the image
 * @return {@link BufferedImage} containing the captcha image
 */
public BufferedImage createCaptcha(int width, int height)
{
	Captcha captcha = new Captcha.Builder(width, height).addText()
														.addBackground(new GradiatedBackgroundProducer())
														.gimp()
														.addNoise()
														.addBorder()
														.build();
	session.setAttribute(Captcha.NAME, captcha);
	return captcha.getImage();
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:19,代码来源:CaptchaService.java


注:本文中的nl.captcha.Captcha类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。