Security change password at a table with

 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));
    }
Released four original articles · won praise 0 · Views 85

Guess you like

Origin blog.csdn.net/qq_45145240/article/details/104069435