示例#1
0
  public static void main(String args[]) {

    MD5 m = new MD5();
    if (Array.getLength(args) == 0) { // ���û�в���ִ�б�׼��Test Suite

      System.out.println("MD5 DaoTest suite:");
      System.out.println("MD5(\"\"):" + m.getMD5ofStr(""));
      System.out.println("MD5(\"a\"):" + m.getMD5ofStr("a"));
      System.out.println("MD5(\"abc\"):" + m.getMD5ofStr("abc"));
      System.out.println("MD5(\"message digest\"):" + m.getMD5ofStr("message digest"));
      System.out.println(
          "MD5(\"abcdefghijklmnopqrstuvwxyz\"):" + m.getMD5ofStr("abcdefghijklmnopqrstuvwxyz"));
      System.out.println(
          "MD5(\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\"):"
              + m.getMD5ofStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"));
    } else System.out.println("MD5(" + args[0] + ")=" + m.getMD5ofStr(args[0]));
  }
 // 修改密码
 public boolean doSetPwd(String tStrUserId, ServletContext application, HttpSession session) {
   try {
     String sql =
         "UPDATE " + strTableName + " SET strPWD=?,intState=? ,intError=0 WHERE  strUserId=? ";
     db.prepareStatement(sql);
     db.setString(1, MD5.getMD5ofString(strPWD));
     db.setInt(2, Constants.U_STATE_ON);
     db.setString(3, tStrUserId);
     db.executeUpdate();
     // �޸��û���������
     Globa.logger0(
         "修改用户密码", globa.loginName, globa.loginIp, sql, "用户管理", globa.userSession.getStrDepart());
     return true;
   } catch (Exception e) {
     e.printStackTrace();
     return false;
   }
 }
 // 重置用户密码
 public boolean resetPwd(String tWhere) {
   try {
     String sql =
         "UPDATE "
             + strTableName
             + " SET strPWD='"
             + MD5.getMD5ofString(Constants.resetPass)
             + "',intState="
             + Constants.U_STATE_ON
             + " ,intError=0   ".concat(tWhere);
     db.executeUpdate(sql);
     Globa.logger0("重置用户密码", globa.loginName, globa.loginIp, sql, "用户管理", globa.unitCode);
     return true;
   } catch (SQLException e) {
     e.printStackTrace();
     return false;
   }
 }
示例#4
0
  /**
   * ����:MD5������
   *
   * @param input
   * @return
   */
  public static String getMD5ofString(String input) {
    if (input == null || input.trim().equals("")) return null;

    MD5 md5 = new MD5();
    return md5.getMD5ofStr(input);
  }
  // 增加用户
  public boolean add(String strUserId) {
    String strSql = "";
    strId = UID.getID();
    try {
      // 把用户信息写入数据库
      strSql =
          "INSERT INTO "
              + strTableName
              + "  (strId, strUserId, strPWD, strName, intError, intState, dBirthday, strSex, strIntro,intType, strUnitId, strUnitCode,"
              + " strNation, strMobile, strEmail, strMsnQQ,strOPhone, strHPhone, strDuty, strStation, intLoginNum, dLatestLoginTime,fOnlineTime, strCaNO, "
              + "strDepart, strCssType,  strLinkAdd, strCreator, dtCreatTime,intUserType) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,str_to_date(?,'%Y-%m-%d %T'),?,?,?,?,?,?,str_to_date(?,'%Y-%m-%d %T'),?)";
      db.prepareStatement(strSql);
      db.setString(1, strId);
      db.setString(2, strUserId.replaceAll(" ", ""));
      db.setString(3, MD5.getMD5ofString(Constants.resetPass)); // strPWD
      db.setString(4, strName);
      db.setInt(5, 0);
      db.setInt(6, 0);
      db.setString(7, dBirthday);
      db.setString(8, strSex);
      db.setString(9, strIntro);
      db.setInt(10, intType);
      db.setString(11, strUnitId);
      db.setString(
          12,
          ""); // strUnitCode                  new Unit(globa, false).retFieldValue("strUnitCode",
               // strUnitId)
      db.setString(13, strNation);
      db.setString(14, strMobile);
      db.setString(15, strEmail);
      db.setString(16, strMsnQQ);
      db.setString(17, strOPhone);
      db.setString(18, strHPhone);
      db.setString(19, strDuty);
      db.setString(20, strStation);
      db.setInt(21, intLoginNum);
      db.setString(22, Format.getDateTime());
      db.setDouble(23, 0);
      db.setString(24, strCaNO);
      db.setString(25, strDepart);
      db.setString(26, strCssType);
      db.setString(27, strLinkAdd);
      db.setString(28, globa.loginName);
      db.setString(29, Format.getDateTime());
      db.setInt(30, intUserType);

      if (db.executeUpdate() > 0) {
        Globa.logger0(
            "增加用户信息",
            globa.loginName,
            globa.loginIp,
            strSql,
            "用户管理",
            globa.userSession.getStrDepart());
        return true;
      } else return false;
    } catch (Exception e) {
      System.out.println("增加用户信息时出错!!");
      e.printStackTrace();
      return false;
    }
  }