Create a registration code for your software

Source: Internet
Author: User

"Turn to the master" -- create a registration code for your own software
From today on, You can encrypt any software you develop if you want -- create a registration machine for your software!

After reading this article, you can confidently tell your users: "Hey, do you want to use my software? Pay for it! ".

Oh, of course, this is just to give yourself a brave words, now even universal registration machine has, what people are afraid? But as long as you think about Microsoft, the encryption technology of other Chinese people will be "despised "? But aren't people making a lot of money in China?

OK. Let's get started.

Like General Software registration, we register here as follows:

1. Generate a 24-bit machine code based on your hardware information.
-- Equivalent to a seed used to generate a random number
2. Use the registration machine to generate a 24-digit registration code based on feature numbers
-- Equivalent to a pseudo-random number generator. The output length is set by yourself. Finally, a formatting function is used to map the random number to the ASCII character set.
3. the user entered the registration code and registered successfully.

Assume that the customer is fond of your software and does not crack it. He needs to obtain the registration code from you in the following ways:

(1) If he can access the Internet, he needs to email you the machine code;

(2) If he cannot access the Internet, he can send the machine code to you via text message.

(3) if he does not have a mobile phone, he can take the machine code and take the train to your office to ask for a registration code.

-- The 3rd message is only intended to prevent you from reading the post. Sorry.

Now, after you get the client's machine code, if you receive money from the client, it seems that you want to encrypt the software for money? Then you can use the customer's machine code to generate a unique registration code and then give it to the user in the same way. Finally, the user can enter the registration code!

It should be emphasized that there are many ways to obtain hardware information of the customer's machine. here we choose the two most reassuring hardware: the serial number of the cup and the volume number of the hard disk. now, you can create a software registration machine step by step.

Step 1: the code for obtaining the cup serial number and hard disk serial number is as follows:

Public String getcpu () <br/>{< br/> string strcpu = NULL; <br/> managementclass mycpu = new managementclass ("win32_processor "); <br/> managementobjectcollection mycpuconnection = mycpu. getinstances (); <br/> foreach (managementobject myobject in mycpuconnection) <br/>{< br/> strcpu = myobject. properties ["processorid"]. value. tostring (); <br/> break; <br/>}return strcpu; <br/>}

// Obtain the volume ID of the device's hard disk <br/> Public String getdiskvolumeserialnumber () <br/> {<br/> managementclass MC = new managementclass ("win32_networkadapterconfiguration "); <br/> managementobject disk = new managementobject ("win32_logicaldisk.deviceid =/" D:/""); <br/> disk. get (); <br/> return disk. getpropertyvalue ("volumeserialnumber "). tostring (); </P> <p>}

Step 2: collect hardware information and generate a machine code. The Code is as follows:

// Generate the machine code <br/> private void button#click (Object sender, eventargs e) <br/>{< br/> label2.text = getcpu () + getdiskvolumeserialnumber (); // obtain the 24-bit CPU and hard disk serial number <br/> string [] Strid = new string [24]; </P> <p> for (INT I = 0; I <24; I ++) // assign the character to the array <br/> {<br/> Strid [I] = label2.text. substring (I, 1); <br/>} label2.text = ""; <br/> random rdid = new random (); <br/> for (INT I = 0; I <24; I ++) // randomly extracts 24 characters from the array to form a new character generation machine 3 <br/> {<br/> label2.text + = Strid [rdid. next (0, 24)]; <br/>}< br/>}

Step 3: use the machine code to generate the Software Registration Code. The Code is as follows:

Public int [] intcode = new int [127]; // used to store the key <br/> Public void setintcode () // assign a random number less than 10 to the array. <br/>{< br/> random Ra = new random (); <br/> for (INT I = 1; I <intcode. length; I ++) <br/>{< br/> intcode [I] = Ra. next (0, 9); <br/>}</P> <p> Public int [] intnumber = new int [25]; // ASCII value used to store the machine code <br/> Public char [] charcode = new char [25]; // storage machine code word <br/> // generate Registration Code <br/> private void button2_click (obje CT sender, eventargs e) <br/>{< br/> If (label2.text! = "") <Br/> {// store the machine code into an array <br/> setintcode (); // initialize the 127-Bit Array <br/> for (INT I = 1; I <charcode. length; I ++) // store the machine code in the array <br/>{< br/> charcode [I] = convert. tochar (label2.text. substring (I-1, 1); <br/>}// <br/> for (Int J = 1; j <intnumber. length; j ++) // Save the ASCII value of the character into an integer group. <Br/> {<br/> intnumber [J] = intcode [convert. toint32 (charcode [J])] + convert. toint32 (charcode [J]); <br/>}< br/> string strasciiname = NULL; // used to store the machine code <br/> for (Int J = 1; j <intnumber. length; j ++) <br/>{< br/> // MessageBox. show (convert. tochar (intnumber [J]). tostring (); <br/> If (intnumber [J]> = 48 & intnumber [J] <= 57) // determine whether the character ASCII value is between 0-9 <br/>{< br/> strasciiname + = convert. tochar (intnumber [J]). tostring (); <br/>}< br/> else if (intnumber [J] >=65 & intnumber [J] <= 90) // determine whether the ASCII value of the character is between A-Z <br/>{< br/> strasciiname + = convert. tochar (intnumber [J]). tostring (); <br/>}< br/> else if (intnumber [J] >=97 & intnumber [J] <= 122) // determine whether the ASCII value of a character is between A and z <br/>{< br/> strasciiname + = convert. tochar (intnumber [J]). tostring (); <br/>}< br/> else // the ASCII value of the character is not in the above range <br/> {<br/> If (intnumber [J]> 122) // determine whether the ASCII value of the character is greater than z <br/>{< br/> strasciiname + = convert. tochar (intnumber [J]-10 ). tostring (); <br/>}< br/> else <br/> {<br/> strasciiname + = convert. tochar (intnumber [J]-9 ). tostring (); <br/>}< br/> label3.text = strasciiname; // get the registration code <br/>}< br/> else <br/>{< br/> MessageBox. show ("select generate machine code", "registration prompt"); <br/>}< br/>}

Step 4: Enter the registration code to register the software. The Demo code is as follows:

Private void btnregist_click (Object sender, eventargs e) <br/>{< br/> If (label3.text! = "") <Br/>{< br/> If (textbox1.text. trimend (). equals (label3.text. trimend () <br/>{< br/> Microsoft. win32.registrykey retkey = Microsoft. win32.registry. currentuser. opensubkey ("software", true ). createsubkey ("Zhy "). createsubkey ("Zhy. ini "). createsubkey (textbox1.text. trimend (); <br/> retkey. setvalue ("username", "mysoft"); <br/> MessageBox. show ("registered"); <br/>}< br/> else {MessageBox. show ("incorrect registration code") ;}< br/>}< br/> else <br/>{< br/> MessageBox. show ("Please generate registration code", "registration prompt"); <br/>}< br/>}

From: http://www.cnblogs.com/ziyiFly/archive/2008/09/22/1296096.html

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.