ʵÏÖÔÀí£ºÍ¨¹ýÅжÏÓû§µÄµÇ½´ÎÊýÒÔ¼°ÉèÖõ½ÆÚʱ¼äÓëϵͳÏÖÓÐʱ¼ä¶Ô±È£¬Á½ÕßÖ®ÖÐÓÐһΪ·Ç·¨ÔòÌáʾÈí¼þµ½ÆÚ¡£ ÆäÖÐ×Ö·û´®¶Ô±Èͨ¹ýMD5¡£ ÎÒÏëÒ»¿ªÊ¼°ÑtxtÉèÖÃΪÒþ²ØÄ£Ê½£¬¶øÊÔÓÃÆÚÒ»¹ý¾Íɾ³ýtxtÎļþ£¬Ó¦¸Ã×öµ½±È½ÏºÃµÄЧ¹û£¬»¶ÓÌÖÂÛ£¡ msn:yun15291li@hotmail.com QQ:17664554 package Admin.Control; import java.io.*; import java.security.MessageDigest; import Admin.Control.MD5; import java.util.*; /** *
Title: *****ϵͳ
*
Description: ****ϵͳ
*
Copyright: Copyright (c) 2004
*
Company: ±±¾©´óѧÈí¼þѧԺ
* @author ÔÆ¹ã * @version 1.0 */ public class ControlValid { private final String REGISTERNUMBER; //¼ÓÃܵÄÔʼ×Ö·û´® private String md5Number; //MD5¼ÓÃܺóµÄ×Ö·û´® private String writeContent; //ÐèҪдÈëÎı¾µÄÄÚÈÝ private int loginTimesLimit; //µÇ½´ÎÊýÏÞÖÆ private static int loginTimesTrue; //Óû§µÄʵ¼ÊµÇ½´ÎÊý private MD5 md5Object; //ʵÀý»¯MD5¶ÔÏó private Calendar cal; //ÈÕÆÚʱ¼äÀà private int orderTime; //É趨µÄϵͳµ½ÆÚʱ¼ä //¹¹Ôì·½·¨½øÐгõʼ»¯¸³Öµ public ControlValid() { REGISTERNUMBER = "ÄãÏëÊäÈëµÄÕýÈ·ÑéÖ¤×Ö·û´®"; md5Object = new MD5(); loginTimesLimit = 99; loginTimesTrue = 0; writeContent = null; cal = Calendar.getInstance(); orderTime = 0; } //·µ»Ø¾¹ýMD5¼ÓÃܹýµÄ×Ö·û´® public String returnMd5String() { try { //µÃµ½¾¹ýMD5¼ÓÃܹýµÄ×Ö·û´® md5Number = md5Object.MD5(REGISTERNUMBER); return md5Number; } catch (Exception e) { return null; } } //½«×Ö·û´®Ð´½øÖ¸¶¨Îı¾ public void writeFile() { try { String returnFileString; int returnLastLoginTimes = 0; //Calendar cal = Calendar.getInstance(); //²âÊÔ»ñµÃϵͳʱ¼ä int currentDate = cal.get(cal.YEAR) + (cal.get(cal.MONTH) + 1) + cal.get(cal.DAY_OF_MONTH); //System.out.println(currentDate); //ÐèҪдÈëÎı¾ÎļþµÄ×Ö·û´® String returnInitDate = this.readFile("InitDate.txt"); orderTime = Integer.parseInt(returnInitDate); returnFileString = this.readFile("ControlValid.txt"); //»ñµÃ»»ÐеÄλÖà int pos = returnFileString.indexOf("\n"); if (pos != -1) { returnLastLoginTimes = Integer.parseInt(returnFileString.substring(pos+1, pos+3)); } loginTimesTrue = returnLastLoginTimes; this.setLoginTimesTrue(); //¸ù¾ÝÈÕÆÚºÍÓû§µÇ½´ÎÊýÅжÏдÈëµÄ×Ö·û´® if ( (currentDate < orderTime) && (this.getLoginTimesTrue() < loginTimesLimit)) { //writeContent = this.returnMd5String() + "\n" + this.getLoginTimesTrue(); writeContent = this.returnMd5String() + "\r" + this.getLoginTimesTrue(); } else { //Ëæ»ú²úÉúÒ»Êý×Ö½øÐÐÊäÈë Random ranInt = new Random(); //int randomInt = ; writeContent = String.valueOf(ranInt.nextInt(10000000))+ "\r" + this.getLoginTimesTrue(); } //½«¼ÓÃܹýµÄ×Ö·û´®Ð´ÈëÎı¾Îļþ File f = new File("ControlValid.txt"); if (!f.exists()) { f.createNewFile(); } DataOutputStream outFile = new DataOutputStream( new BufferedOutputStream( new FileOutputStream(f))); byte[] byteWriteContent = writeContent.getBytes(); outFile.write(byteWriteContent); outFile.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } //ÔÚÖ¸¶¨Îı¾ÖжÁÈ¡Êý¾Ý public String readFile(String fileName) { String sLine = "",sResult = ""; boolean testFirstLine=true; try { DataInputStream inFile = new DataInputStream( new BufferedInputStream( new FileInputStream(fileName))); while ( (sLine = inFile.readLine()) != null) { if (testFirstLine) { sResult = sLine; testFirstLine=false; } else { sResult += "\n" + sLine; } } inFile.close(); return sResult; } catch (Exception e) { return null; } } //×¢²á×Ö·û´®ÓëÎı¾Öзµ»ØµÄ×Ö·û´®¶Ô±È public boolean ContractRegisterString() { String returnFileString; String md5String; String returnMd5String = ""; int i = 0; returnFileString = this.readFile("ControlValid.txt"); //»ñµÃ»»ÐеÄλÖà int pos = returnFileString.indexOf("\n"); if (pos != -1) { returnMd5String = returnFileString.substring(0,pos); } md5String = this.returnMd5String(); //System.out.println(returnFileString); //µÃµ½¾¹ýMD5¼ÓÃܹýµÄ×Ö·û´® if (md5String.equals(returnMd5String)) { return true; } else { return false; } } //Óû§Ã¿µÇ½һ´Î¾Í°Ñʵ¼ÊµÇ½´ÎÊý±äÁ¿¼Ó1 public void setLoginTimesTrue() { loginTimesTrue += 1; } //·µ»ØÓû§Êµ¼ÊµÇ½´ÎÊý public static int getLoginTimesTrue() { return loginTimesTrue; } //Ö÷·½·¨²âÊÔÓà public static void main(String[] args) { // int i = 0; ControlValid controlValid = new ControlValid(); //ÉèÖõǽ´ÎÊý // for (i = 0; i < 25; i++) { // controlValid.setLoginTimesTrue(); // } //дÈëÄÚÈݵ½Îļþ controlValid.writeFile(); controlValid.ContractRegisterString(); } }

