日期:2014-05-19 浏览次数:20627 次
else if(action.equals("/regist")){ String username=request.getParameter("username"); String name=request.getParameter("name"); String pwd=request.getParameter("pwd1"); String sex=request.getParameter("sex"); String number=request.getParameter("number"); HttpSession session=request.getSession(); String number1=(String) session.getAttribute("number"); //System.out.println(number+" "+number1); if(!number.equals(number1)){ request.setAttribute("error", "验证码错误,请重新输入"); request.getRequestDispatcher("regist.jsp").forward(request, response); return; } MessageDigest md; String Pwd = null; try { md = MessageDigest.getInstance("MD5"); byte[] buf=md.digest(pwd.getBytes()); BASE64Encoder encoder=new BASE64Encoder(); Pwd=encoder.encode(buf); } catch (NoSuchAlgorithmException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } User u=new User(); u.setUsername(username); u.setName(name); u.setPwd(Pwd); u.setSex(sex); EmployeeDao dao=(EmployeeDao) DAOFactory.getInstance("EmployeeDao"); try { dao.regist(u); request.getRequestDispatcher("login.jsp").forward(request, response); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
------解决方案--------------------
密码类型的 一般用11楼所说的那样
------解决方案--------------------
public static void md5(String src) { char psw = '*'; char srcArray[] = src.toCharArray(); System.out.print("加密后:"); for (int i = 0; i < src.length(); i++) { srcArray[i] = (char) (srcArray[i] ^ psw); System.out.print(srcArray[i]); } System.out.println(""); System.out.print("加密前:"); for (int i = 0; i < src.length(); i++) { srcArray[i] = (char) (srcArray[i] ^ psw); System.out.print(srcArray[i]); } System.out.println(); }