vue springboot修改密码
时间: 2023-11-19 18:56:49 浏览: 264
Vue和Springboot可以实现修改密码功能。具体实现步骤如下:
1.前端页面设计:在Vue中设计一个修改密码的页面,包括原密码、新密码和确认新密码三个输入框,以及一个提交按钮。
2.前端密码加密:在前端使用SM4.js对新密码进行加密,然后将加密后的密码和原密码一起发送给后端。
3.后端密码解密:在Springboot后端接收到前端发送的密码后,使用SM4解密新密码,然后将原密码和解密后的新密码进行比对,如果一致则修改密码成功。
4.修改密码接口:在Springboot中编写一个修改密码的接口,接收前端发送的原密码和加密后的新密码,进行密码比对和修改。
下面是一个简单的修改密码的代码示例:
前端代码:
```
<template>
<div>
<input type="password" v-model="oldPassword" placeholder="请输入原密码">
<input type="password" v-model="newPassword" placeholder="请输入新密码">
<input type="password" v-model="confirmPassword" placeholder="请确认新密码">
<button @click="changePassword">提交</button>
</div>
</template>
<script>
import SM4 from '@/utils/SM4.js'
export default {
data() {
return {
oldPassword: '', newPassword: '',
confirmPassword: ''
}
},
methods: {
changePassword() {
if (this.newPassword !== this.confirmPassword) {
alert('两次输入的密码不一致')
return
}
const sm4 = new SM4('1234567890123456', '1234567890123456')
const encryptedPassword = sm4.encrypt(this.newPassword)
// 发送原密码和加密后的新密码给后端
}
}
}
</script>
```
后端代码:
```
@RestController
@RequestMapping("/user")
public class UserController {
@PostMapping("/changePassword")
public String changePassword(@RequestParam String oldPassword, @RequestParam String newPassword) {
// 解密新密码
SM4 sm4 = new SM4("1234567890123456", "1234567890123456")
String decryptedPassword = sm4.decrypt(newPassword)
// 比对原密码和解密后的新密码
if (checkPassword(oldPassword) && checkPassword(decryptedPassword)) {
// 修改密码
updatePassword(decryptedPassword)
return "success"
} else {
return "fail"
}
}
}
```
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![ppt](https://img-home.csdnimg.cn/images/20241231044937.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![docx](https://img-home.csdnimg.cn/images/20241231044901.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)