Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package service;
- import dao.DaoFactory;
- import dao.interfaces.UserDao;
- import entity.User;
- import service.exceptions.AccountServiceException;
- import utils.Utils;
- import static utils.Lang._;
- public class AccountService {
- public void updateUserPassword(User user, String oldPw, String newPw, String newPwAgain) throws AccountServiceException {
- if(oldPw == null || oldPw.isEmpty()) throw new AccountServiceException(_("Altes Passwort muss ausgefüllt sein!"));
- if(newPw == null || newPw.isEmpty()) throw new AccountServiceException(_("Neues Passwort muss ausgefüllt sein!"));
- if(newPwAgain == null || newPwAgain.isEmpty()) throw new AccountServiceException(_("Neues Passwort wiederholen muss ausgefüllt sein!"));
- if(!newPw.equals(newPwAgain)) throw new AccountServiceException(_("Neues Passwort und neues Passwort wiederholen müssen gleich sein!"));
- if(newPw.length() < 6) throw new AccountServiceException(_("Das Passwort muss mindestens 6 Zeichen lang sein!"));
- if(newPw.length() > 100) throw new AccountServiceException(_("Das Passwort darf maximal 100 Zeichen lang sein!"));
- if(!user.getPasswordhash().equals(Utils.getSHA256ValueOf(oldPw))) throw new AccountServiceException(_("Das eingegebene alte Passwort ist falsch!"));
- user.setPasswordhash(Utils.getSHA256ValueOf(newPw));
- UserDao userDao = (UserDao) DaoFactory.findDaoByEntity(User.class);
- userDao.merge(user);
- }
- }
Add Comment
Please, Sign In to add comment