前后端分离 用户名密码加密
自己写了个简单的用户名密码加密功能,仅供参考。环境springbootvue流程就是先获取一个随机口令,然后将用户名和密码拼在口令的后面,后台再提取出来1.登录前获取随机口令@RequestMapping(value = "/uuu", method = {RequestMethod.GET})public ReturnBean uuu() {String ...
·
自己写了个简单的用户名密码加密功能,仅供参考。环境springboot vue
流程就是先获取一个随机口令,然后将用户名和密码拼在口令的后面,后台再提取出来
1.登录前获取随机口令
@RequestMapping(value = "/uuu", method = {RequestMethod.GET})
public ReturnBean uuu() {
String uid = UUID.randomUUID().toString();
session.setAttribute("uid",uid);
return ReturnBean.success(uid);
}
2.前端将用户名和密码拼在口令的后面
Login({
col1: this.uuu+this.userName,
col2: this.uuu+this.password
}).then((res) => {
//处理返回信息
})
3.后端解析传过来的用户名和密码
private User getUser( String col1,String col2){
if(session.getAttribute("uid")==null){
throw new Exception("认证失败");
}
if(StringUtils.isBlank(col1)||StringUtils.isBlank(col2)){
throw new Exception("认证失败");
}
String uid = session.getAttribute("uid").toString();
if((!col1.startsWith(uid))||(!col2.startsWith(uid))){
throw new Exception("认证失败");
}
String userName = col1.replace(uid,"");
String pw = col2.replace(uid,"");
User user = new User();
user.setUserName(userName);
user.setPassword(pw);
return user;
}更多推荐



所有评论(0)