@Override public boolean changePassword(String password, Session session) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String username = authentication.getName(); JSONObject o = new JSONObject(password); String currentPass = o.getString("currentPass"); String newPass = o.getString("newPass"); String hQLquey = new StringBuilder("update Users set password="******":newpass") .append(" where username=:username") .toString(); if (authentication.isAuthenticated() && Utils.verifyPassword(username, currentPass, session)) { int status = session .createQuery(hQLquey) .setString("newpass", Utils.encryptPass(newPass)) .setString("username", username) .executeUpdate(); if (status == 1) { return true; } } return false; }
@Override public boolean createUser(Users user, UsersInfo usersInfo, Session session) { if (!Utils.isExists(user.getUsername())) { user.setPassword(Utils.encryptPass(user.getPassword())); usersInfo.setUsers(user); session.save(user); return true; } return false; }