When developing software for commercial purposes, the registration code and activation code become very important. Today's software cracking technology is really strong, and various large domestic and foreign software has a registration mechanism, but it is also constantly cracked. The following is just a common version. It is easier to break the source code, but we are learning the technology. Of course, in the future, your software will not be easily cracked.
Step 1. Machine code is generated based on the volume label and CPU serial number
// Obtain the volume ID of the device's hard disk
Public static string getdiskvolumeserialnumber ()
{
Managementclass MC = new managementclass ("win32_networkadapterconfiguration ");
Managementobject disk = new managementobject ("win32_logicaldisk.deviceid =" D :"");
Disk. Get ();
Return disk. getpropertyvalue ("volumeserialnumber"). tostring ();
}
// Obtain the CPU serial number
Public static 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;
}
// Generate the machine code
Public static string getmnum ()
{
String strnum = getcpu () + getdiskvolumeserialnumber (); // obtain the 24-bit CPU and hard disk serial number
String strmnum = strnum. substring (0, 24); // extract the first 24 characters from the generated string as the machine code
Return strmnum;
}
Public static int [] intcode = new int [127]; // store the key
Public static int [] intnumber = new int [25]; // ASCII value of the stored machine code
Public static char [] charcode = new char [25]; // stores machine code
Public static void setintcode () // number of values assigned to the array smaller than 10
{
For (INT I = 1; I <intcode. length; I ++)
{
Intcode [I] = I % 9;
}
}
Step 2. Generate a registration code based on the machine code
// Generate the registration code
Public static string getrnum ()
{
Setintcode (); // initialize the 127-Bit Array
For (INT I = 1; I <charcode. length; I ++) // store the machine code in the array
{
Charcode [I] = convert. tochar (getmnum (). substring (I-1, 1 ));
}
For (Int J = 1; j <intnumber. length; j ++) // Save the ASCII value of the character to an integer group.
{
Intnumber [J] = intcode [convert. toint32 (charcode [J])] + convert. toint32 (charcode [J]);
}
String strasciiname = ""; // used to store the registration code
For (Int J = 1; j <intnumber. length; j ++)
{
If (intnumber [J]> = 48 & intnumber [J] <= 57) // determines whether the ASCII value of a character is between 0-9.
{
Strasciiname + = convert. tochar (intnumber [J]). tostring ();
}
Else if (intnumber [J]> = 65 & intnumber [J] <= 90) // determines whether the ASCII value of a character is between A-Z
{
Strasciiname + = convert. tochar (intnumber [J]). tostring ();
}
Else if (intnumber [J]> = 97 & intnumber [J] <= 122) // determines whether the ASCII value of a character is a-Z.
{
Strasciiname + = convert. tochar (intnumber [J]). tostring ();
}
Else // determines that the ASCII value of a character is not in the above range
{
If (intnumber [J]> 122) // determines whether the ASCII value of a character is greater than Z.
{
Strasciiname + = convert. tochar (intnumber [J]-10). tostring ();
}
Else
{
Strasciiname + = convert. tochar (intnumber [J]-9). tostring ();
}
}
}
Return strasciiname;
}
Step 3. Check the registration status. If no registration is available, you can customize the trial.
/// <Summary>
/// Check registration
/// </Summary>
Private void checkregist ()
{
This. btn_reg.enabled = true;
Registrykey retkey = Microsoft. win32.registry. currentuser. opensubkey ("software", true). createsubkey ("wxk"). createsubkey ("wxk. ini ");
Foreach (string strrnum in retkey. getsubkeynames () // determines whether to register
{
If (strrnum = clstools. getrnum ())
{
Thcontrol (true );
Return;
}
}
Thcontrol (false );
Thread Th1 = new thread (New threadstart (thcheckregist2 ));
Th2.start ();
}
}
/// <Summary>
/// Verification trial times
/// </Summary>
Private Static void thcheckregist2 ()
{
MessageBox. Show ("you are using a trial version. You can try this software for 3000000 times for free !", "Prompt", messageboxbuttons. OK, messageboxicon. information );
Int32 tlong;
Try
{
Tlong = (int32) Registry. getvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", 0 );
MessageBox. Show ("Thank you for using" + tlong + "Times", "prompt", messageboxbuttons. OK, messageboxicon. information );
}
Catch
{
Registry. setvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", 0, registryvaluekind. DWORD );
MessageBox. Show ("welcome new users to use this software", "prompt", messageboxbuttons. OK, messageboxicon. information );
}
Tlong = (int32) Registry. getvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", 0 );
If (tlong <3000000)
{
Int times = tlong + 1;
Registry. setvalue ("HKEY_LOCAL_MACHINE \ SOFTWARE \ Angel", "usetimes", times );
}
Else
{
MessageBox. Show ("trial times have arrived", "warning", messageboxbuttons. OK, messageboxicon. Warning );
Application. Exit ();
}
}
C # generate a software registration code