一 验证码

登录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. 吴裕雄--天生自然 R语言开发学习:聚类分析

    #-------------------------------------------------------# # R in Action (2nd ed): Chapter 16 # # Clu ...

  2. JAVA WEB期末项目第二阶段成果

    我们做的系统是一个基于Java web与MySQL的食堂订餐系统 班级: 计科二班 小组成员:李鉴宣.袁超 1.开发环境 开发编辑器使用:Visual Studio Code 数据库使用:MySQL8 ...

  3. React.js/HTML5和iOS双向通信

    最近,我使用WKWebView和React.js进行双向通信,自己写了React.js嵌入到Native中. Native操作Web,通过两种方式传值 第一种,通过JS传值给Native 通过这种方式 ...

  4. 【U创营学员招募】8节免费云计算课程,让你轻松掌握生产技能

    课程不错,免费听课.免费听课.免费听课,强烈推荐-! 公众号对话框回复"课程助手" 即可报名! ---END---

  5. ActiveMQ学习总结(一)

    自己写的网上商城项目中使用了ActiveMQ,虽然相比于RabbitMQ,kafka,RocketMQ等相比,ActiveMQ可能性能方面不是最好的选择,不过消息队列其实原理区别不大,这里对学过的关于 ...

  6. JavaScript 設計模型 - Iterator

    Iterator Pattern是一個很重要也很簡單的Pattern:迭代器!我們可以提供一個統一入口的迭代器,Client只需要知道有哪些方法,或是有哪些Concrete Iterator,並不需要 ...

  7. php-fpm启动失败处理

    报错信息: No pool defined. at least one pool section must be specified in config file [11-Mar-2019 23:57 ...

  8. 工作技术点小计14条 hybrid + animate 方向

    设置transition 动画的时候 , js直接设置duration 和 变化值不会起作用 , 需要先设置duration , 等一小会再设置变化值 安卓端 , 窗口不可见时 , window.in ...

  9. 跟我猜Spring-boot:依赖注入

    依赖注入 引&目标 本篇是<跟我猜Spring-Boot>系列的第二篇(Oh,我竟然已经写了10篇了,真不容易). 在上一篇中,我们实现了Bean的创建,但是仅仅是创建而已,并没有 ...

  10. 神奇的 SQL 之 ICP → 索引条件下推

    开心一刻 楼主:来,我们先排练一遍 小伙伴们:好 嘿.哈.嚯 楼主:非常好,就是这个节奏,我们开始吧 楼主:啊.啊.啊,疼 ! 你们是不是故意的 ? 回表与覆盖索引 正式讲 ICP 之前了,我们先将相 ...