• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Captcha类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: createCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
@Test
public void createCaptcha()
{
	BufferedImage captchaImg = captchaService.createCaptcha(100, 75);
	assertEquals(captchaImg.getWidth(), 100);
	assertEquals(captchaImg.getHeight(), 75);
	verify(httpSession).setAttribute(eq(Captcha.NAME), any(Captcha.class));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:9,代码来源:CaptchaServiceTest.java


示例17: validateCaptcha

import nl.captcha.Captcha; //导入依赖的package包/类
@Test
public void validateCaptcha() throws CaptchaException
{
	Captcha captcha = new Captcha.Builder(100, 75).build();
	when(httpSession.getAttribute(Captcha.NAME)).thenReturn(captcha);
	assertTrue(captchaService.validateCaptcha(captcha.getAnswer()));
	assertFalse(captchaService.validateCaptcha("invalid_answer"));
	assertTrue(captchaService.validateCaptcha(captcha.getAnswer()));
	verify(httpSession, times(0)).removeAttribute(Captcha.NAME);
	verify(httpSession, times(0)).setAttribute(eq(Captcha.NAME), any(Object.class));
}
 
开发者ID:molgenis,项目名称:molgenis,代码行数:12,代码来源:CaptchaServiceTest.java


示例18: processAction

import nl.captcha.Captcha; //导入依赖的package包/类
public GenericBean processAction(ActionRequest request, ActionResponse response) throws Exception {
  // Determine the project container to use
  Project project = findProject(request);
  if (project == null) {
    throw new Exception("Project is null");
  }

  // Check the user's permissions
  User user = getUser(request);
  if (!user.isLoggedIn()) {
    throw new PortletException("User needs to be logged in");
  }

  // Determine the database connection to use
  Connection db = useConnection(request);

  // Track replies to previous messages
  PrivateMessage inboxPrivateMessage = null;

  // Populate all values from the request
  PrivateMessage privateMessage = (PrivateMessage) PortalUtils.getFormBean(request, PrivateMessage.class);
  if (privateMessage.getLinkModuleId() != Constants.PROJECT_MESSAGES_FILES) {
    privateMessage.setProjectId(project.getId());
    int linkProjectId = getLinkProjectId(db, privateMessage.getLinkItemId(), privateMessage.getLinkModuleId());
    if (linkProjectId == -1) {
      linkProjectId = project.getId();
    }
    privateMessage.setLinkProjectId(linkProjectId);
  } else {
    //reply to a message from the inbox, so the project id needs to be the profile of user who sent the message
    inboxPrivateMessage = new PrivateMessage(db, privateMessage.getLinkItemId());
    int profileProjectIdOfEnteredByUser = UserUtils.loadUser(inboxPrivateMessage.getEnteredBy()).getProfileProjectId();
    privateMessage.setProjectId(profileProjectIdOfEnteredByUser);
    privateMessage.setParentId(inboxPrivateMessage.getId());

    //update the last reply date of the message
    inboxPrivateMessage.setLastReplyDate(new Timestamp(System.currentTimeMillis()));
  }
  privateMessage.setEnteredBy(user.getId());

  // Validate the form
  if (!StringUtils.hasText(privateMessage.getBody())) {
    privateMessage.getErrors().put("bodyError", "Message body is required");
    return privateMessage;
  }

  // Check for captcha if this is a direct message (not a reply)
  if ("true".equals(PortalUtils.getApplicationPrefs(request).get(ApplicationPrefs.USERS_CAN_REGISTER)) &&
      privateMessage.getLinkModuleId() != Constants.PROJECT_MESSAGES_FILES &&
      privateMessage.getProjectId() > -1) {
    if (privateMessage.getProject().getProfile() && !TeamMemberList.isOnTeam(db, privateMessage.getProjectId(), user.getId())) {
      LOG.debug("Verifying the captcha...");
      String captcha = request.getParameter("captcha");
      PortletSession session = request.getPortletSession();
      Captcha captchaValue = (Captcha) session.getAttribute(Captcha.NAME);
      session.removeAttribute(Captcha.NAME);
      if (captchaValue == null || captcha == null ||
          !captchaValue.isCorrect(captcha)) {
        privateMessage.getErrors().put("captchaError", "Text did not match image");
        return privateMessage;
      }
    }
  } else {
    LOG.debug("Captcha not required");
  }

  // Insert the private message
  boolean inserted = privateMessage.insert(db);
  if (inserted) {
    // Update the message replied to
    if (inboxPrivateMessage != null && inboxPrivateMessage.getId() != -1) {
      inboxPrivateMessage.update(db);
    }
    // Send email notice
    PortalUtils.processInsertHook(request, privateMessage);
  }
  // Close the panel, everything went well
  String ctx = request.getContextPath();
  response.sendRedirect(ctx + "/close_panel_refresh.jsp");
  return null;
}
 
开发者ID:Concursive,项目名称:concourseconnect-community,代码行数:82,代码来源:SavePrivateMessageAction.java


示例19: isValid

import nl.captcha.Captcha; //导入依赖的package包/类
/**
 * Gets the valid attribute of the RegisterBean object
 *
 * @param session http session for captcha check
 * @return The valid value
 */
public boolean isValid(PortletSession session) {
  String captchaPassed = (String) session.getAttribute("TE-REGISTER-CAPTCHA-PASSED");
  if (!"passed".equals(captchaPassed)) {
    Captcha captchaValue = (Captcha) session.getAttribute(Captcha.NAME);
    session.removeAttribute(Captcha.NAME);
    if (captchaValue == null) {
      LOG.warn("RegisterBean-> Could not find captcha session variable for comparison to user input");
    }
    if (captchaValue == null || captcha == null ||
        !captchaValue.isCorrect(captcha)) {
      errors.put("captchaError", "Text did not match image");
    } else {
      session.setAttribute("TE-REGISTER-CAPTCHA-PASSED", "passed");
    }
  }
  if (!StringUtils.hasText(email)) {
    errors.put("emailError", "Required field");
  } else {
    if (!EmailUtils.checkEmail(email)) {
      errors.put("emailError", "Check the email address entered");
    }
  }
  if (!StringUtils.hasText(nameFirst)) {
    errors.put("nameFirstError", "Required field");
  }
  if (!StringUtils.hasText(nameLast)) {
    errors.put("nameLastError", "Required field");
  }
  if (!StringUtils.hasText(country)) {
    errors.put("countryError", "Required field");
  }
  if ("UNITED STATES".equals(country)) {
    if (!StringUtils.hasText(postalCode)) {
      errors.put("postalCodeError", "Required field");
    } else {
      LocationBean location = LocationUtils.findLocationByZipCode(postalCode);
      if (location == null) {
        errors.put("postalCodeError", "Could not locate this zip or postal code");
      }
    }
  }
  return (!hasErrors());
}
 
开发者ID:Concursive,项目名称:concourseconnect-community,代码行数:50,代码来源:RegisterBean.java


示例20: doExecute

import nl.captcha.Captcha; //导入依赖的package包/类
@Override
protected AuthStatusResultBase doExecute(LoginAction action, ExecutionContext context)
    throws AuthenticationException,
    DispatchException {
    U user;

    LoginCaptchaInfo captchaInfo = captchaInfoProvider.get();
    _logger.info("User {} logging in", action.getUserName());
    synchronized (captchaInfo) {
        if (action.getGoogleLoginToken() == null
            && (action.getUserName() == null || action.getPassword() == null)) {
            captchaInfo.registerIncorrectAnswer();
            return new AuthStatusResultBase(captchaInfo.needCaptcha());
        }

        if (captchaInfo.needCaptcha()) {
            // incorrect request
            if (action.getCaptchaAnswer() == null
                || sessionProvider.get().getAttribute(Captcha.NAME) == null
                || !action.getCaptchaAnswer().equals(
                    ((Captcha) sessionProvider.get().getAttribute(Captcha.NAME)).getAnswer())) {
                captchaInfo.registerIncorrectAnswer();
                return new AuthStatusResultBase(captchaInfo.needCaptcha());
            }
        }

        user = findByUserNameAndPassword(
            action.getUserName(),
            action.getPassword(),
            action.isGoogleLogin(),
            action.getGoogleLoginToken(),
            action.getLoginProductType());
        if (user == null) {
            // incorrect password
            captchaInfo.registerIncorrectAnswer();
            return new AuthStatusResultBase(captchaInfo.needCaptcha());
        } else {
            captchaInfo.registerCorrectAnswer();
        }
    }

    R result = createResultBase();
    setUserToSession(user, result, action.getUserName());

    // if the login was successful and the user wants to stay signed in
    if (result.isSuccess() && action.isNeedStaySignedIn()) {
        String UUIDString = UUID.randomUUID().toString();
        result.setUserEmail(user.getUserAuthString());
        result.setUserUUID(UUIDString);
        // set the UUID for the user
        setUserStaySignedInUUID(result.getUserId(), UUIDString);
    }

    _logger.debug("Login successful: {}", authStatProvider.get());
    return result;
}
 
开发者ID:inepex,项目名称:ineform,代码行数:57,代码来源:AbstractLoginHandler.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CommandInfo类代码示例发布时间:2022-05-22
下一篇:
Java TransformerFactoryImpl类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap