public Result resetPwd(@RequestParam(name="id")Integer id,
@RequestParam(name="password")String password,
@RequestParam(name="newPassword")String newPassword){
//password为用户输入的原密码,oldPassword为数据库中的原密码
User oldUser = userService.getById(id);
String oldPassword = oldUser.getPassword();
//通过matches判断加密后密码一致性
boolean f = passwordEncoder.matches(password,oldPassword);
if(!f){
throw new UserException(MessageEnum.PAEAMETER_VALIDATION_ERROR);
}
User user = new User();
user.setId(id);
user.setPassword(passwordEncoder.encode(newPassword));
return ResultUtil.success(userService.updateById(user));
}
Security在同一张表里修改密码
最新推荐文章于 2024-05-01 16:49:56 发布