com.wf.captcha.utils.CaptchaUtil Java Examples
The following examples show how to use
com.wf.captcha.utils.CaptchaUtil.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainController.java From easyweb-shiro with MIT License | 6 votes |
/** * 登录 */ @ResponseBody @PostMapping("/login") public JsonResult doLogin(String username, String password, String code, HttpServletRequest request) { if (StringUtil.isBlank(username, password)) { return JsonResult.error("账号密码不能为空"); } if (!CaptchaUtil.ver(code, request)) { CaptchaUtil.clear(request); return JsonResult.error("验证码不正确"); } try { UsernamePasswordToken token = new UsernamePasswordToken(username, password); SecurityUtils.getSubject().login(token); addLoginRecord(getLoginUserId(), request); return JsonResult.ok("登录成功"); } catch (IncorrectCredentialsException ice) { return JsonResult.error("密码错误"); } catch (UnknownAccountException uae) { return JsonResult.error("账号不存在"); } catch (LockedAccountException e) { return JsonResult.error("账号被锁定"); } catch (ExcessiveAttemptsException eae) { return JsonResult.error("操作频繁,请稍后再试"); } }
Example #2
Source File: UserController.java From MOOC with MIT License | 6 votes |
@RequestMapping(value = "quickregist") // 快速注册 public ModelAndView insertUser(String varcode, User user, HttpSession session, HttpServletRequest req, ModelAndView mav) { String id = DateUtil.getId(); String username = user.getUsername(); mav.setViewName("redirect:course"); if (varcode == null) { return mav; } if (userBiz.selectUser(username) == 1 || !CaptchaUtil.ver(varcode, req)) { return mav; } user.setId(id); user.setMission(null); user.setBuycase(null); user.setMycase(null); user.setVip(null); userBiz.insertSelective(user); session.setAttribute("loginUser", user); setlog(user, req.getRemoteAddr(), "快速注册"); return mav; }
Example #3
Source File: UserController.java From MOOC with MIT License | 6 votes |
@RequestMapping(value = "regist") // 注册 public ModelAndView regist(ModelAndView mav, String varcode, User user, HttpSession session, HttpServletRequest req) { String id = DateUtil.getId(); String username = user.getUsername(); mav.setViewName("redirect:course"); if (varcode == null) { return mav; } if (userBiz.selectUser(username) == 1 || !CaptchaUtil.ver(varcode, req)) { return mav; } user.setId(id); user.setMission(null); user.setBuycase(null); user.setMycase(null); user.setVip(null); userBiz.insertSelective(user); setlog(user, req.getRemoteAddr(), "普通注册"); return mav; }
Example #4
Source File: MainController.java From MOOC with MIT License | 6 votes |
@RequestMapping(value = "changevarcode")//更换验证码,验证码显示 public void changevarcode(HttpServletRequest req,HttpServletResponse res) throws IOException, FontFormatException { /*String url=req.getServletContext().getRealPath("/varcodeimg")+"\\"+varcodeurl+".jpg";*/ //验证码生成 varcodenumber为验证码的值 /* url=req.getServletContext().getRealPath("/varcodeimg")+"\\"+varcodeurl+".jpg";*/ //写出到response的输出流中 /*String varcodenumber = NubmerToJpgUtil.NumberToJpgUtil(res.getOutputStream()); session.setAttribute("varcodenumber",varcodenumber);*/ //使用新的验证码 // 设置位数 //CaptchaUtil.out(5, req, res); // 设置宽、高、位数 //CaptchaUtil.out(130, 48, 5, req, res); // 使用gif验证码 GifCaptcha gifCaptcha = new GifCaptcha(130,48,4); gifCaptcha.setFont(gifCaptcha.FONT_7); CaptchaUtil.out(gifCaptcha,req, res); }
Example #5
Source File: VerifyImageUtil.java From kk-anti-reptile with Apache License 2.0 | 5 votes |
public VerifyImageDTO generateVerifyImg() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String result = CaptchaUtil.out(outputStream); String base64Image = "data:image/jpeg;base64," + Base64.getEncoder().encodeToString(outputStream.toByteArray()); String verifyId = UUID.randomUUID().toString(); return new VerifyImageDTO(verifyId, null, base64Image, result); }
Example #6
Source File: ValidateCodeController.java From microservices-platform with Apache License 2.0 | 5 votes |
/** * 创建验证码 * * @throws Exception */ @GetMapping(SecurityConstants.DEFAULT_VALIDATE_CODE_URL_PREFIX + "/{deviceId}") public void createCode(@PathVariable String deviceId, HttpServletResponse response) throws Exception { Assert.notNull(deviceId, "机器码不能为空"); // 设置请求头为输出图片类型 CaptchaUtil.setHeader(response); // 三个参数分别为宽、高、位数 GifCaptcha gifCaptcha = new GifCaptcha(100, 35, 4); // 设置类型:字母数字混合 gifCaptcha.setCharType(Captcha.TYPE_DEFAULT); // 保存验证码 validateCodeService.saveImageCode(deviceId, gifCaptcha.text().toLowerCase()); // 输出图片流 gifCaptcha.out(response.getOutputStream()); }
Example #7
Source File: LoginController.java From kvf-admin with MIT License | 5 votes |
@Log("登录") @PostMapping(value = "login") public R login(@RequestParam("username") String username, @RequestParam("password") String password, boolean rememberMe, String vercode) { // 只有开启了验证码功能才需要验证。可在yml配置kvf.login.authcode.enable来开启或关闭 if (needAuthCode) { // 验证码校验 HttpServletRequest request = HttpServletContextKit.getHttpServletRequest(); if (!CaptchaUtil.ver(vercode, request)) { CaptchaUtil.clear(request); // 清除session中的验证码 return R.fail("验证码不正确"); } } try { Subject subject = ShiroKit.getSubject(); UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe); subject.login(token); ShiroKit.setSessionAttribute("user", username); } catch (Exception e) { LOGGER.error(e.getMessage(), e); return R.fail(e.getMessage()); } return R.ok(); }
Example #8
Source File: LoginController.java From kvf-admin with MIT License | 5 votes |
/** * 图片验证码 */ @GetMapping(value = "captcha") public void captcha(HttpServletRequest request, HttpServletResponse response) throws IOException { // 可在yml配置kvf.login.authcode.dynamic切换动静态图片验证码,默认静态 // 其它验证码样式可前往查看:https://gitee.com/whvse/EasyCaptcha if (isDynamic) { CaptchaUtil.out(new GifCaptcha(), request, response); } else { CaptchaUtil.out(request, response); } }
Example #9
Source File: MainController.java From easyweb-shiro with MIT License | 5 votes |
/** * 图形验证码,用assets开头可以排除shiro拦截 */ @RequestMapping("/assets/captcha") public void captcha(HttpServletRequest request, HttpServletResponse response) { try { CaptchaUtil.out(request, response); } catch (IOException e) { e.printStackTrace(); } }
Example #10
Source File: MainController.java From MOOC with MIT License | 5 votes |
@RequestMapping(value = "varcodecheck")//验证码验证 public void varcodecheck(String varcode,HttpServletRequest req,HttpServletResponse res) throws IOException { res.setCharacterEncoding("utf-8"); PrintWriter pw = res.getWriter(); /*String var = (String) session.getAttribute("varcodenumber");*/ if(!CaptchaUtil.ver(varcode, req)){ pw.write("0"); } }
Example #11
Source File: LoginControll.java From rebuild with GNU General Public License v3.0 | 5 votes |
@RequestMapping("user-login") public void userLogin(HttpServletRequest request, HttpServletResponse response) { String vcode = getParameter(request, "vcode"); Boolean needVcode = (Boolean) ServletUtils.getSessionAttribute(request, NEED_VCODE); if (needVcode != null && needVcode && (StringUtils.isBlank(vcode) || !CaptchaUtil.ver(vcode, request))) { writeFailure(response, lang("InputWrong", "Captcha")); return; } final String user = getParameterNotNull(request, "user"); final String password = ServletUtils.getRequestString(request); int retry = getLoginRetryTimes(user, 1); if (retry > 3 && StringUtils.isBlank(vcode)) { ServletUtils.setSessionAttribute(request, NEED_VCODE, true); writeFailure(response, "VCODE"); return; } String hasError = LoginToken.checkUser(user, password); if (hasError != null) { writeFailure(response, hasError); return; } User loginUser = Application.getUserStore().getUser(user); loginSuccessed(request, response, loginUser.getId(), getBoolParameter(request, "autoLogin", false)); // 清理 getLoginRetryTimes(user, -1); ServletUtils.setSessionAttribute(request, NEED_VCODE, null); writeSuccess(response); }
Example #12
Source File: SignUpControll.java From rebuild with GNU General Public License v3.0 | 4 votes |
@RequestMapping("captcha") public void captcha(HttpServletRequest request, HttpServletResponse response) throws IOException { Font font = new Font(Font.SERIF, Font.BOLD & Font.ITALIC, 22 + RandomUtils.nextInt(8)); int codeLen = 4 + RandomUtils.nextInt(3); CaptchaUtil.out(160, 41, codeLen, font, request, response); }
Example #13
Source File: CaptchaServlet.java From EasyCaptcha with Apache License 2.0 | 4 votes |
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { CaptchaUtil.out(request, response); }