Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void changePassword(String login, String currentClearTextPassword, String newPassword) {
- userRepository.findOneByLogin(login)
- .ifPresent(user -> {
- String currentEncryptedPassword = user.getUserSecret();
- String encryptedInputPassword = "";
- try {
- encryptedInputPassword = authUtils.encrypt(currentClearTextPassword);
- } catch (Exception ex) {
- System.err.println("Encryption exception: " + ex.getMessage());
- }
- if (!Objects.equals(encryptedInputPassword, currentEncryptedPassword)) {
- throw new Exception("Invalid Password"); // <-- unhandled exception
- }
- String encryptedNewPassword = "";
- try {
- encryptedNewPassword = authUtils.encrypt(newPassword);
- } catch (Exception ex) {
- System.err.println("Encryption exception: " + ex.getMessage());
- }
- user.setUserSecret(encryptedNewPassword);
- userRepository.save(user);
- log.debug("Changed password for User: {}", user);
- });
- }
Add Comment
Please, Sign In to add comment