Guest User

Untitled

a guest
Jul 24th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. public void changePassword(String login, String currentClearTextPassword, String newPassword) {
  2.  
  3. userRepository.findOneByLogin(login)
  4. .ifPresent(user -> {
  5. String currentEncryptedPassword = user.getUserSecret();
  6. String encryptedInputPassword = "";
  7. try {
  8. encryptedInputPassword = authUtils.encrypt(currentClearTextPassword);
  9. } catch (Exception ex) {
  10. System.err.println("Encryption exception: " + ex.getMessage());
  11. }
  12. if (!Objects.equals(encryptedInputPassword, currentEncryptedPassword)) {
  13. throw new Exception("Invalid Password"); // <-- unhandled exception
  14. }
  15. String encryptedNewPassword = "";
  16. try {
  17. encryptedNewPassword = authUtils.encrypt(newPassword);
  18. } catch (Exception ex) {
  19. System.err.println("Encryption exception: " + ex.getMessage());
  20. }
  21. user.setUserSecret(encryptedNewPassword);
  22. userRepository.save(user);
  23. log.debug("Changed password for User: {}", user);
  24. });
  25. }
Add Comment
Please, Sign In to add comment