一 验证码

登录login.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>xxx需求管理系统</title>
</head>
<script src="${pageContext.request.contextPath}/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
$(function () {
$("#login").click(function () {
var url="${pageContext.request.contextPath}/login"
var json={"username":$("#username").val(),"password":$("#password").val(),"checkcode":$("#checkcode").val()};
if($("#username").val()==""){
alert("用户名不能为空")
}else if($("#password").val()==""){
alert("密码不能为空")
}else {
function callback(msg) {
if(msg==0){
alert("用户名或密码错误")
}else if(msg==1){ alert("验证码错误!")
}else if(msg==2){
window.location.href="${pageContext.request.contextPath}/toSxf";
}
}
}
$.get(url,json,callback);
})
})
</script>
<body>
<div align="center" style="margin-top: 150px">
<h2 style="color: blue">xxx需求管理系统登录界面</h2>
用户名:<input type="text" name="username" id="username"></br></br>
密&nbsp &nbsp码:<input type="password" name="password" id="password"></br></br>
<table align="center">
<tr>
<td>验证码:</td>
<td class="width50"><input id="checkcode" name="checkcode" type="text" class="width50" /></td>
<td><img src="createImage" alt="验证码" title="点击更换" onclick="this.src='createImage?'+(new Date()).getTime();"/></td>
<td><span id="checkcode_msg" class="required"></span></td>
</tr>
</table>
<input type="submit" value="登录" id="login">
<a href="${pageContext.request.contextPath}/toForgetPwd">忘记密码?</a>
<a href="${pageContext.request.contextPath}/toUpdatePwd">修改密码?</a>
</div>
</body>
</html>

后台处理 loginController

@RequestMapping("/login")
public void login(String username, String password,String checkcode, HttpServletResponse response,HttpSession session) throws IOException {
String code =(String) session.getAttribute("number");
if (service.login(username,password)==null) {
response.getWriter().println(0);
} else if(checkcode==null||checkcode.length()==0||!code.equalsIgnoreCase(checkcode)){
response.getWriter().println(1);
}else{
response.getWriter().println(2);
}
}
@GetMapping("/createImage")
public void createImage(HttpServletResponse response, HttpSession session) throws IOException {
BufferedImage image = new BufferedImage(80, 30, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random r = new Random();
g.setColor(new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
g.fillRect(0, 0, 80, 20);
//获取生成的验证码
String code = getNumber();
//绑定验证码
session.setAttribute("number", code);
g.setFont(new Font(Font.SANS_SERIF, Font.BOLD, 25));
g.setColor(new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255)));
g.drawString(code, 5, 25);
//设置消息头
response.setContentType("image/jpeg");
OutputStream os = response.getOutputStream();
ImageIO.write(image, "jpeg", os);
}
public String getNumber(){
String str = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String code = "";
for(int i= 0;i<4;i++){
int index = (int)(Math.random()*str.length());
code+=str.charAt(index);
}
return code;
}

二 邮箱(主要功能:输入用户名,将重置密码发往注册时与用户名绑定的邮箱)

在你的 application.yml中加入

spring:
mail:
host: (发送者邮箱类型)
       form:      (发送者邮箱用户名)
       port: 25

       username:  (发送者邮箱用户名)

       password:  (发送者邮箱密码)
@Autowired
private JavaMailSender javaMailSender; @Value("${spring.mail.username}")
private String username; @RequestMapping("/forgetPwd")
public ModelAndView getPwd(HttpServletResponse response,String loginName) throws IOException {
ModelAndView mv=new ModelAndView();
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setFrom(username);
simpleMailMessage.setTo( service.getMail(loginName));//目的邮箱
simpleMailMessage.setSubject("重置密码"); //邮箱主题
simpleMailMessage.setText("重置的密码为123456789");//邮箱内容 自定义
javaMailSender.send(simpleMailMessage);
mv.setViewName("login/success");
return mv;
}

spring Boot登录验证之验证码 邮箱的更多相关文章

  1. Spring Security登录验证流程源码解析

    一.登录认证基于过滤器链 Spring Security的登录验证流程核心就是过滤器链.当一个请求到达时按照过滤器链的顺序依次进行处理,通过所有过滤器链的验证,就可以访问API接口了. SpringS ...

  2. spring boot 登录注册 demo (四) -- 体验小结

    之前没有折腾过Spring,直接上来怼Spring Boot异常痛苦,参考着官网的guide(https://spring.io/guides)写了几个demo: spring boot 跑起来确是方 ...

  3. 2-功能1:基于用户认证组件和Ajax实现登录验证(图片验证码)

    1.登录页面的设计 (1)label标签的id属性 label标签的id属性,点击label标记,相当于点击了input框 bootstarp样式 class="form-group&quo ...

  4. spring boot 登录认证

    玩转spring boot——简单登录认证 https://www.cnblogs.com/GoodHelper/p/6343190.html 玩转spring boot——简单登录认证 https: ...

  5. Spring Boot系列(四) Spring Boot 之验证

    这节没有高深的东西, 但有一些学习思路值得借鉴. JSR 303 (Bean Validation) Maven依赖 <dependency> <groupId>org.spr ...

  6. spring boot 登录注册 demo (二) -- 数据库访问

    通过data-jpa来访问数据库 <dependency> <groupId>org.springframework.boot</groupId> <arti ...

  7. spring boot 登录注册 demo (一)

    Welcome to Spring Boot 代码结构 src/main/java 下 controller层,路由功能dao层,数据库的访问domain,bean的存放service,业务层appl ...

  8. VC POST表单——登录验证新浪邮箱

    1.本机环境: Windows XP SP3.ADSL 2.开发工具: WildPackets OmniPeek V5.1.4 Visual C++ 6.0 IE6.0 FlexEdit V2.3.1 ...

  9. SpringMVC+Apache Shiro+JPA(hibernate)案例教学(三)给Shiro登录验证加上验证码

    序: 给Shiro加入验证码,有多种方式,当然你也可以通过继承修改FormAuthenticationFilter类,通过Shiro去验证验证码.具体实现请百度: 应用Shiro到Web Applic ...

随机推荐

  1. ES6下的Function.bind方法

    在JavaScript的使用中,this的指向问题始终是一个难点.不同的调用方式,会使this指向不同的对象.而使用call,apply,bind等方式,可改变this的指向,完成一些令人惊叹的黑魔法 ...

  2. VS自身的单元测试方法DEMO

    ///用来修饰测试类 [TestClass()] public class Program { private TestContext testContextInstance; /// <sum ...

  3. SpringMVC基本使用步骤

    使用Spring MVC,第一步就是使用Spring提供的前置控制器,即Servlet的实现类DispatcherServlet拦截url:org.springframework.web.servle ...

  4. 关于(Building tool)的认识以及当下流行的Building tool有哪些?

    1.Building tool是什么? (Building tool)构建工具是一种工具,它负责构建流程的所有内容,并自动化与构建项目相关的所有内容.它致力于以下任务: 生成源代码(如果在软件项目中使 ...

  5. java连接sqlserver数据简单操作

    首先我们下载微软的JDBC驱动包 https://www.microsoft.com/en-us/download/details.aspx?id=11774 下载好后我们打开如下图 点击Unzip ...

  6. 借助mkcert签发本地证书

    mkcert 是由 Filippo Valsorda 使用go语言开源的一款零配置搭建本地证书服务的工具,它可以兼容Window, Linux, macOS等多种开发平台,省去了我们自签本地证书的繁琐 ...

  7. STM32F103驱动ADS1118

    ADS1118 作为常用温度测量芯片被越来越多的开发者熟知,TI官方给出的是基于 MSP430 的驱动测试程序,由于 STM32 的普及,闲暇中移植了 MSP430 的 ADS1118 驱动程序到 S ...

  8. 2——PHP defined()函数

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  9. 痞子衡嵌入式:恩智浦i.MX RT1xxx系列MCU启动那些事(11.2)- FlexSPI NOR连接方式大全(RT1060/1064(SIP))

    大家好,我是痞子衡,是正经搞技术的痞子.今天痞子衡给大家介绍的是恩智浦i.MX RT1060/1064(SIP)两款MCU的FlexSPI NOR启动的连接方式. 上一篇文章<FlexSPI N ...

  10. ADO.NET中DataTable类的使用

    DataTable类将关系数据表示为表格形式.在创建DataTable之前,必须包含System.Data名称空间.ADO.NET提供了一个DataTable类来独立创建和使用数据表.它也可以和Dat ...