public String modifyPassWord() throws Exception { UserbaseinfoDAO userDao = (UserbaseinfoDAO) DAOFactory.getIUserbaseinfoDAOInstance(); String useroldPassword = request.getParameter("myoldPassword"); String usernewPassword = request.getParameter("mynewPassword"); String userId = (String) ServletActionContext.getRequest().getSession().getAttribute("userId"); String DaoUserPass = userDao.getUserAllMsgById(Integer.parseInt(userId)).getUserPassword(); boolean Istrue = true; boolean Isrepeat = true; MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] md = md5.digest(useroldPassword.getBytes()); useroldPassword = new String(md); byte[] md1 = md5.digest(usernewPassword.getBytes()); usernewPassword = new String(md1); // 如果旧密码与数据库密码不匹配,提示用户错误消息 if (!DaoUserPass.equals(useroldPassword)) { Istrue = false; } else { // 比较新密码与原始密码是否一致,如果一致,提示用户新密码与旧密码不能一致 if (!DaoUserPass.equals(usernewPassword) && usernewPassword != "") { // 如果不一致,修改数据库中的密码 Isrepeat = false; // 没有重复 System.out.println("用户id=" + userId + "用户新密码=" + usernewPassword); DAOFactory.getIUserbaseinfoDAOInstance() .updatePassword(Integer.parseInt(userId), usernewPassword); } } System.out.println(Istrue + " " + Isrepeat); response.getWriter().print("[{\"isTrue\":" + Istrue + "},{\"isRepeat\":" + Isrepeat + "}]"); return null; }
public String updateMsgMail() { int userId = Integer.parseInt((String) request.getSession().getAttribute("userId")); UserbaseinfoDAO userDAO = (UserbaseinfoDAO) DAOFactory.getIUserbaseinfoDAOInstance(); userDAO.updateUserMsgMail(user, userId); try { showInformation(); } catch (IOException e) { e.printStackTrace(); } return "toUpdate"; }