Create a registration code for your software

Source: Internet
Author: User

From: http://www.csharpwin.com/csharpspace/2337.shtml

There is: http://msdn.microsoft.com/zh-cn/library/system.componentmodel.licenseprovider (V = vs.80). aspx

From today on, You can encrypt any software you develop if you want -- create a registration machine for your software!

After reading this articleArticleYou can confidently tell your users: "Hello, 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. First, generate based on the user's hardware information24BitMachine code
-- Equivalent to a seed used to generate a random number
2. Use the registration machine to generate a 24Bit registration code
-- 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. User entered registration code registration successful

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 the machine code to you;

(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 first article is for you to read 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: Obtain the cup serial number and hard disk serial numberCodeAs follows:

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

 

 
Public String getdiskvolumeserialnumber () {managementclass MC = new managementclass ("win32_networkadapterconfiguration"); managementobject disk = new managementobject ("disks = \" D: \ ""); disk. get (); Return disk. getpropertyvalue ("volumeserialnumber "). tostring ();}

 

 

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

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

 

 

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 save the public void setintcode () Key () // assign a random number less than 10 to the array {random Ra = new random (); For (INT I = 1; I <intcode. length; I ++) {intcode [I] = Ra. next (0, 9) ;}} public int [] intnumber = new int [25]; // The ASCII value used to store the machine code public char [] charcode = new char [25]; // store the machine code word // generate the registration code private void button2_click (Object sender, eventargs E) {If (label2.text! = "") {// Save the machine code to the array setintcode (); // initialize the 127-Bit Array for (INT I = 1; I <charcode. length; I ++) // store the machine code into the Array {charcode [I] = convert. tochar (label2.text. substring (I-1, 1);} // For (Int J = 1; j <intnumber. length; j ++) // Save the ASCII value of the character into an integer group. {Intnumber [J] = intcode [convert. toint32 (charcode [J])] + convert. toint32 (charcode [J]);} string strasciiname = NULL; // used to store the machine code for (Int J = 1; j <intnumber. length; j ++) {// MessageBox. show (convert. tochar (intnumber [J]). tostring (); // determines whether the ASCII value of a character is 0-9. If (intnumber [J]> = 48 & intnumber [J] <= 57) {strasciiname + = convert. tochar (intnumber [J]). tostring ();} // determines whether the ASCII value of a character is between A-Z else if (intnumber [J]> = 65 & intnumber [J] <= 90 {strasciiname + = convert. tochar (intnumber [J]). tostring ();} // determines whether the ASCII value of a character is between A and Z. Else if (intnumber [J]> = 97 & intnumber [J] <= 122) {strasciiname + = convert. tochar (intnumber [J]). tostring ();} else // determines that the ASCII value of the character is not in the above range {If (intnumber [J]> 122) // determine whether the ASCII value of the character is greater than z {strasciiname + = convert. tochar (intnumber [J]-10 ). tostring ();} else {strasciiname + = convert. tochar (intnumber [J]-9 ). tostring () ;}} label3.text = strasciiname; // get the registration code} else {MessageBox. show ("select generate machine code", "registration prompt ");}}

 

 

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

 

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

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.