Guest User

Untitled

a guest
Apr 21st, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. package service;
  2.  
  3. import dao.DaoFactory;
  4. import dao.interfaces.UserDao;
  5. import entity.User;
  6. import service.exceptions.AccountServiceException;
  7. import utils.Utils;
  8. import static utils.Lang._;
  9.  
  10. public class AccountService {
  11. public void updateUserPassword(User user, String oldPw, String newPw, String newPwAgain) throws AccountServiceException {
  12. if(oldPw == null || oldPw.isEmpty()) throw new AccountServiceException(_("Altes Passwort muss ausgefüllt sein!"));
  13. if(newPw == null || newPw.isEmpty()) throw new AccountServiceException(_("Neues Passwort muss ausgefüllt sein!"));
  14. if(newPwAgain == null || newPwAgain.isEmpty()) throw new AccountServiceException(_("Neues Passwort wiederholen muss ausgefüllt sein!"));
  15. if(!newPw.equals(newPwAgain)) throw new AccountServiceException(_("Neues Passwort und neues Passwort wiederholen müssen gleich sein!"));
  16. if(newPw.length() < 6) throw new AccountServiceException(_("Das Passwort muss mindestens 6 Zeichen lang sein!"));
  17. if(newPw.length() > 100) throw new AccountServiceException(_("Das Passwort darf maximal 100 Zeichen lang sein!"));
  18. if(!user.getPasswordhash().equals(Utils.getSHA256ValueOf(oldPw))) throw new AccountServiceException(_("Das eingegebene alte Passwort ist falsch!"));
  19.  
  20. user.setPasswordhash(Utils.getSHA256ValueOf(newPw));
  21.  
  22. UserDao userDao = (UserDao) DaoFactory.findDaoByEntity(User.class);
  23. userDao.merge(user);
  24. }
  25. }
Add Comment
Please, Sign In to add comment