Control the software trial period source code (novice three hours of results) (original)

Source: Internet
Author: User
Tags date integer md5 readfile return string
Control | original | Source code implementation principle: By judging the number of user login and set the expiration time and the system existing time contrast, one of the two is illegal to prompt software expiration. Where the string contrast passes through the MD5. I would like to start with the TXT set to hidden mode, and the probationary period after the deletion of TXT file, should do better results, welcome to discuss! Msn:yun15291li@hotmail.com qq:17664554 Package Admin.control; Import java.io.*; Import Java.security.MessageDigest; Import Admin.Control.MD5; Import java.util.*; /** *
Title: * * * System
*
Description: * * * * System
*
Copyright:copyright (c) 2004
*
Company: Software Institute of Peking University
* @author Cloud * @version 1.0/public class Controlvalid {private final string registernumber;//encrypted original string private string Md5number; MD5 encrypted string private string writecontent; Content that needs to be written to the text private int logintimeslimit; The number of landing limits private static int logintimestrue; User's actual landing times private MD5 md5object; Instantiate the MD5 object private Calendar cal; Date Time class private int ordertime; Set the system expiration//construct method to initialize the assignment public controlvalid () {registernumber = "The correct validation string you want to enter"; md5object = new MD5 (); logintimeslimit = 99; logintimestrue = 0; Writecontent = null; Cal = Calendar.getinstance (); Ordertime = 0; //Returns the encrypted string public string returnmd5string () {try {///MD5 encrypted string md5number = Md5object.md5 (registernumber) after MD5; ret Urn Md5number; catch (Exception e) {return null;}} Writes a string to the specified text public void WriteFile () {try {String returnfilestring; int returnlastlogintimes = 0;//calendar cal = Calen Dar.getinstance (); The test gets the system time 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") that needs to be written to a text file; Ordertime = Integer.parseint (returninitdate); returnfilestring = This.readfile ("ControlValid.txt"); Gets the position of the newline int pos = returnfilestring.indexof ("\ n"); if (POS!=-1) {returnlastlogintimes = Integer.parseint (returnfilestring.substring (pos+1, pos+3));} logintimestrue = ret Urnlastlogintimes; This.setlogintimestrue (); To determine the written string if (CurrentDate < Ordertime) && (This.getlogintimestrue () < Logintimeslimit), based on the date and the number of user logons {//w Ritecontent = this.returnmd5string () + "\ n" + this.getlogintimestrue (); Writecontent = this.returnmd5string () + "\ r" + this.getlogintimestrue (); else {///randomly generate a number for input Random ranint = new Random ();//int randomint =; writecontent = string.valueof (ranint.nextint (1000 0000) + "\ r" + this.getlogintimestrue (); ///write encrypted string to text 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 ());}} Reads the data public string ReadFile (string fileName) {String sline = "", Sresult = "" in the specified text; Boolean testfirstline=true; try {datainputstream inFile = new DataInputStream (new Bufferedinputstream (FileName)); while (sLi NE = Infile.readline ())!= null) {if (testfirstline) {sresult = sline; testfirstline=false;} else {sresult = "\ n" + S Line; } infile.close (); return sresult; catch (Exception e) {return null;}} The registration string contrasts with the string returned in the text public boolean contractregisterstring () {string returnfilestring; String md5string; String returnmd5string = ""; int i = 0; returnfilestring = This.readfile ("ControlValid.txt"); Gets the position of the newline int pos = returnfilestring.indexof ("\ n"); if (POS!=-1) {returnmd5string = returnfilestring.substring (0,pos);} md5string = This.returNmd5string (); System.out.println (returnfilestring); Gets the MD5 encrypted string if (Md5string.equals (returnmd5string)) {return true;} else {return false;}} Every time the user log on the actual landing number variable plus 1 public void setlogintimestrue () {logintimestrue + = 1;}//back to the actual number of user login public static int Getlogintime Strue () {return logintimestrue}//Main method test with public static void main (string[] args) {//int i = 0; Controlvalid controlvalid = new Controlvalid (); Set number of login/for (i = 0; i < i++) {//Controlvalid.setlogintimestrue ();/////write content to file Controlvalid.writefile (); Controlvalid.contractregisterstring (); } }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.