重置密码

impl:
@Override
public JSONObject updatePassword(Long id, String password, String newPassword) {
UserEntity userEntity = getById(id);

//List<UserDto> user = userDao.findUserById(id);
JSONObject obj = new JSONObject();
if(DigestUtils.sha256Hex(password).equals(userEntity.getPassword())){
userEntity.setPassword(DigestUtils.sha256Hex(newPassword));

boolean f = this.update(userEntity,
new QueryWrapper<UserEntity>().eq("id",id));

obj.put("b",f);
if(!f){
obj.put("msg","修改失败,请联系管理员!");
}else{
obj.put("msg","修改成功!");

}

}else{
obj.put("b",true);
obj.put("msg","用户名或密码错误!");

}
return obj;
}

public static void main(String[] args) {
String pwd="123456";
System.out.println(DigestUtils.sha256Hex(pwd));
}



controller:
/**
* 修改登录用户密码
*/

@PostMapping("/upPassword")
@ApiOperation("修改密码")
@RequiresPermissions("sys:user:upPassword")
public Response upPassword(Long id,String password,String newPassword){

JSONObject obj = userService.updatePassword(id, password, newPassword);



return Response.ok().put("upPwd",obj);
posted @ 2022-02-15 11:12  孤家、寡人  阅读(110)  评论(0)    收藏  举报