PwdChangeAction.java
上传用户:dlqqsh
上传日期:2021-11-13
资源大小:7840k
文件大小:3k
源码类别:

OA系统

开发平台:

Java

  1. package officeol.mc.actions;
  2. import org.apache.struts.action.ActionMapping;
  3. import org.apache.struts.action.ActionForm;
  4. import javax.servlet.http.HttpServletRequest;
  5. import javax.servlet.http.HttpServletResponse;
  6. import org.apache.struts.action.ActionForward;
  7. import org.apache.struts.action.Action;
  8. import officeol.mc.tools.*;
  9. public class PwdChangeAction extends Action {
  10.     public ActionForward execute(ActionMapping mapping, ActionForm form,
  11.                                  HttpServletRequest request,
  12.                                  HttpServletResponse response) {
  13.         try{
  14.             request.setCharacterEncoding("GBK");
  15.             Tool tl = new Tool();
  16.             String un = StringFilter.filter(tl.isNull(request.getParameter(
  17.                     "un").trim()));
  18.             String pwd = StringFilter.filter(tl.isNull(request.getParameter(
  19.                     "pwd").trim()));
  20.             String pwd1 = StringFilter.filter(tl.isNull(request.getParameter(
  21.                     "pwd1").trim()));
  22.             String pwd2 = StringFilter.filter(tl.isNull(request.getParameter(
  23.                     "pwd2").trim()));
  24.             DBConn dbc = new DBConn();
  25.             if(un!=null){
  26.                 if(pwd!=null){
  27.                     if(pwd1!=null&&pwd2!=null){
  28.                         String csql = "select * from [user] where username = '" +
  29.                                       un + "' and password = '"+tl.hash(pwd)+"'";
  30.                         if(dbc.getArray(csql)!=null){
  31.                             if(pwd1.equals(pwd2)){
  32.                                 String sql = "update [user] set password ='"+
  33.                                              tl.hash(pwd2)+"' where username = '"+un+"'";
  34.                                 dbc.executeUpdate(sql);
  35.                                  request.setAttribute("msg","修改成功!请紧记新密码 "+pwd2);
  36.                             }else{
  37.                                 request.setAttribute("msg","两次输入新密码必须相同!");
  38.                             }
  39.                         }else{
  40.                             request.setAttribute("msg","旧密码输入错误!");
  41.                         }
  42.                     }else{
  43.                         request.setAttribute("msg","两次输入新密码都不能为空!");
  44.                     }
  45.                 }else{
  46.                     request.setAttribute("msg","原密码不能为空!");
  47.                 }
  48.             }else{
  49.                 request.setAttribute("msg","用户名不能为空!");
  50.             }
  51.         }catch(Exception ex){
  52.             ex.printStackTrace();
  53.             request.setAttribute("msg","出现异常,请重试!");
  54.         }
  55.         return mapping.findForward("succ");
  56.     }
  57. }