一 验证码

登录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. Linux Ubuntu 安装SSH服务

    1.安装SSH命令:sudo apt-get install openssh-server 2.启动SSH服务命令:/etc/init.d/ssh start 3.停止SSH服务命令:/etc/ini ...

  2. Heartbeat(注意iptables和selinux的问题)

    安装 yum –y install heartbeat libnet配置 通过yum安装配置文件目录/etc/ha.d目录下没有配置文件需要从doc目录中复制三个文件.ha.cf.authkeys.h ...

  3. PO设计模式-实现移动端自动化测试

    开发环境:python 3.6.5 + selenium 2.48.0 + pytest框架 + Android 5.1 工具:pycharm + Appium + Genymotion 测试机型:S ...

  4. 浅谈JobExecutionContext & JobDataMap

    JobExecutionContext是什么? 当Scheduler调用一个Job,就会将JobExecutionContext传递给Job的 execute() 方法: Job能通过JobExecu ...

  5. (一)mybatis简易搭建

    mybatis(基础及其搭建) 声明:该文章及该分类中的内容均基于正在开发的项目和一本参考书(深入浅出MyBatis技术原理与实战    by 杨开振) 一.mybatis核心组件(简要介绍) Sql ...

  6. Python---13面向对象编程

    一.类和实例 面向对象最重要的概念就是类(Class)和实例(Instance),必须牢记类是抽象的模板,比如Student类,而实例是根据类创建出来的一个个具体的“对象”,每个对象都拥有相同的方法, ...

  7. 神经网络的Python实现(一)了解神经网络

    网络上深度学习相关博客教程质量参差不齐,很多细节很少有文章提到,所以本着夯实深度学习基础的想法写下此系列博文. 本文会从神经网络的概述.不同框架的公式推导和对应的基于numpy的Python代码实现等 ...

  8. numpy的array分割

    import numpy as np A = np.arange(12).reshape(3,4) print(A) print(np.split(A,2,axis=1)) print(np.spli ...

  9. Future 异步多线程

    进来接手一个任务,需要做异步多线程数据源调用,数据源的配置和使用请阅读相关文章: https://www.cnblogs.com/haoliyou/p/9604452.html 配置好数据源后,实质上 ...

  10. process.env

    官方: process.env属性返回一个包含用户环境信息的对象.