SpringBoot+JavaMailSender+Redis完整找回密码功能
导入maven坐标
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<!--spring-boot-starter-web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- spring data redis 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<!-- lecttuce 缓存连接池-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.13.1</version>
</dependency>
2.写yml配置文件
spring:
mail:
#邮件发送配置
default-encoding: UTF-8
host: smtp.qq.com
# 授权码
password: xxxxxx
# 邮件发送安全配置
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
timeout: 10000
connectiontimeout: 10000
writetimeout: 10000
# 发件人信息
username: xxxx@qq.com
# springboot整合redis配置
redis:
database: 1
host: ip地址
port: 6379
jedis:
pool:
max-active: 100
max-idle: 10
max-wait: 100000
timeout: 5000
3.编写controller
/**
* 发送验证码
*
* @param email
*/
@GetMapping("/sendCode/{email}")
@ResponseBody
public void sendCode(@PathVariable("email") String email) {
// 产生验证码
String code = RandomUtils.getFourBitRandom();
userService.send(email, code);
}
4.编写service
@Value("${spring.mail.username}")
private String from;
@Autowired
private JavaMailSender mailSender;
@Autowired
private RedisTemplate redisTemplate;
/**
* 发送验证码
*
* @param recipientEmailName 收件人邮箱名
* @param checkCode 验证码
*/
@Override
public void send(String recipientEmailName, String checkCode) {
SimpleMailMessage message = new SimpleMailMessage();
message.setFrom(from); //发送人
message.setTo(recipientEmailName); //收件人
message.setSubject("HomeAppliance系统验证码"); //邮件名
message.setText("您的验证码为【" + checkCode + "】,有效期为2分钟,请确保是本人操作,不要把验证码泄露给其他人!!!"); //邮件内容(验证码)
// 存储验证码 --> redis
redisTemplate.opsForValue().set(recipientEmailName, checkCode, 2, TimeUnit.MINUTES);
mailSender.send(message);
}
5.结果

SpringBoot+JavaMailSender+Redis完整找回密码功能的更多相关文章
- javaWeb实现使用邮箱邮件找回密码功能
JSP+Jmail+JavaBean 发邮件(转)2010-08-23 18:052007年04月14日 14:32/* * SendMail.java * * Created on 2007年3月3 ...
- PHP会员找回密码功能的简单实现
文章来自:博客 http://www.jb51.net/article/91944.htm 设置思路 1.用户注册时需要提供一个E-MAIL邮箱,目的就是用该邮箱找回密码. 2.当用户忘记密码或用户名 ...
- 通过邮件找回密码功能的Java实现
1.有个需求就是,忘记密码后通过邮箱找回.现在的系统在注册的时候都会强制输入邮箱,其一目的就是 通过邮件绑定找回,可以进行密码找回.通过java发送邮件的功能我就不说了,重点讲找回密码. 2.参考别人 ...
- SpringMVC通过邮件找回密码功能的实现
1.最近开发一个系统,有个需求就是,忘记密码后通过邮箱找回.现在的系统在注册的时候都会强制输入邮箱,其一目的就是 通过邮件绑定找回,可以进行密码找回.通过java发送邮件的功能我就不说了,重点讲找回密 ...
- spring mvc下实现通过邮箱找回密码功能
1功能分析 通过spring mvc框架实现通过邮箱找回密码. 2 实现分析 主要是借助某个邮箱的pop3/smtp服务实现的邮件代发功能. 3 源码分析 3.1首先在用户表对应的javabean中加 ...
- PHP会员找回密码功能实现实例介绍
设置思路 1.用户注册时需要提供一个E-MAIL邮箱,目的就是用该邮箱找回密码. 2.当用户忘记密码或用户名时,点击登录页面的“找回密码”超链接,打开表单,并输入注册用的E-MAIL邮箱,提交. 3. ...
- php邮箱找回密码功能
原理很简单: 用户找回密码的时候,填写用户名,程序得到用户名便可以去数据库取出用户对应的密码以及当时填写的邮箱, 根据用户名和密码生成一个key=md5(username+password),然后$s ...
- Android找回密码功能 手机找回、邮箱找回
找回密码功能设计:https://blog.csdn.net/qq_33472765/article/details/82287404?utm_source=blogxgwz0 手机找回:https: ...
- django项目中使用邮箱找回密码功能
本文使用qq邮箱,需要登录邮箱,在设置-账户里面开启SMTP服务,要记下授权码 前端html {#找回密码的表单#} <form action="" method=" ...
随机推荐
- 服务器表单字符串转化Vue表单挂在到对应DOM节点
今天在项目开发中,遇到从后端返回的vue文件(包含template,js,css)的文件,试过用v-html解析文件,渲染到页面,但是无法渲染,后来去查了一堆资料,自己写了一个全局方法来解析这类文件 ...
- Termux劣质的入门指南
直入主题: 1.1 下载安装 Google下载(有条件的用!) F-droid下载(建议使用!) 也可以去酷安下载! 1.2 配置 apt update && apt upgrade ...
- Rancher Fleet使用教程
官方文档: https://fleet.rancher.io/ https://github.com/rancher/fleet 博客截止日期为:20201204 当前官网版本为v0.3.0,但在实践 ...
- POSIX之消息队列
my_semqueue_send.c: #include<stdio.h> #include<errno.h> #include<mqueue.h> #includ ...
- Java 实现订单未支付超时自动取消
在电商上购买商品后,如果在下单而又没有支付的情况下,一般提示30分钟完成支付,否则订单自动.比如在京东下单为完成支付: 超过24小时,就会自动取消订单,下面使用 Java 定时器实现超时取消订单功能. ...
- linux文件时间详细说明
目录 一:文件时间信息 2 文件时间详细说明 一:文件时间信息 1 文件时间信息分类: 三种时间信息 文件修改时间: mtime 属性修改时间: ctime 文件访问时间: atime 2 查看文件时 ...
- vue 快速入门 系列 —— Vue 实例的初始化过程
其他章节请看: vue 快速入门 系列 Vue 实例的初始化过程 书接上文,每次调用 new Vue() 都会执行 Vue.prototype._init() 方法.倘若你看过 jQuery 的源码, ...
- Vue3源码分析之微任务队列
参考资料:https://zh.javascript.info/microtask-queue#wei-ren-wu-dui-lie-microtaskqueue 简化版 Vue3 中的 微任务队列实 ...
- 双系统之删除Linux以及grub的引导
问题阐述:最近玩双系统,把linux系统搞崩了,回到windos备份Linux系统的数据就把Linux的盘格式化了,然后再每当进入系统都会出现grub的命令格的窗口,输入任何命令都报错? 解决方法: ...
- navicat连接mysql报错1251解决方案
感谢原文作者:XDMFC 原文链接:https://blog.csdn.net/xdmfc/article/details/80263215 问题描述 今天下了个 MySQL8.0,发现Navicat ...