How does the C # program do the registration code?

Source: Internet
Author: User
Tags foreach bool config hash md5 tostring
Program

Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.Web.Configuration;
Using Hasher;
<summary>
Summary description of CS
</summary>
///
Namespace CS
{
public class CS
{
Judge the serial number
public bool CSS ()
M is a configuration file value
X is the serial number value
CSS to compare whether the registration code is correct
{
Hasher.hasher hash = new Hasher.hasher ();
String Xulie = hash. Sern ();
String m = ConfigurationManager.AppSettings.Get ("message"). ToString ();

if (m = = Xulie)
{
return true;

}
Else
{
return false;

}

}

public bool Text (string x)
X is a write parameter
Used when the registration code is not correct
{
Hasher.hasher hash = new Hasher.hasher ();
String Xulie = hash. Sern ();
if (x = = Xulie)
{
return true;
}
Else
{
return false;
}
}

public void con (string path, String x)
Write configuration file information
Path is the virtual path of the request
X the value to be modified
{

Configuration config = webconfigurationmanager.openwebconfiguration (path);

Config. AppSettings.Settings.Clear ();
String m = ConfigurationManager.AppSettings.Get ("message");
Config. APPSETTINGS.SETTINGS.ADD ("message", x);
Config. Save ();

}


}
}


Top

Reply Person: wuda8 (C # asp.net 2.0 blog) () Prestige: 93 2006-11-1 15:37:43 Score: 0


?
Using System;
Using System.Data;
Using System.Configuration;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;
Using System.IO;
Using System.Security.Cryptography;
Using System.Management;
<summary>
Summary description of Hasher
</summary>
///
Namespace Hasher
{

public class Hasher
{

Private byte[] _hashkey; Hash Key storage Variable
public string _hashtext; strings to be encrypted
Public Hasher ()
// {
// }


String that needs to produce a cryptographic hash
public string Hashtext
{
Set
{
_hashtext = value;
}
Get
{
return _hashtext;
}
}

Uses the MD5CryptoServiceProvider class to produce a hash value. You do not need to provide a key.
</summary>
<returns></returns>
public string Md5hasher ()
{
byte[] Md5data = System.Text.Encoding.UTF8.GetBytes (Hashtext);

MD5 Md5 = new MD5CryptoServiceProvider ();

Byte[] result = Md5.computehash (md5data);

return convert.tobase64string (Result); Returns a length of 25-byte string
}


Get CPU Serial Number
Public String Getcpuid ()
{
ManagementClass mc = new ManagementClass ("Win32_Processor");
Managementobjectcollection MOC = MC. GetInstances ();

String strcpuid = null;
foreach (ManagementObject mo in MOC)
{
Strcpuid = mo. properties["Processorid"]. Value.tostring ();
Break
}
return strcpuid;
}//end method
Get the hard drive serial number
Public String Getdriveid ()
{
String driveserialnum = "";
Scripting.filesystemobjectclass Mysystem = new Scripting.filesystemobjectclass ();
foreach (Scripting.drive mydriver in mysystem.drives)
{
String serialnumber = "";
Try
{
SerialNumber = MyDriver.SerialNumber.ToString ();
Driveserialnum = Driveserialnum + serialnumber;
}
catch (Exception ex)
{

}

}

return driveserialnum;
}

Public String Strjia ()
{
String Strjiami = "";
Strjiami = Getcpuid () + Getdriveid ();

return Strjiami;
}
public string Jiqixuelie;
public string duijiqima = null;
Get the machine code.
public string Hashgetdriveid ()

{
Hasher hs = new Hasher ();

Hs. Hashtext = Hs.strjia ();
String Jiqi = hs. Md5hasher ();
Duijiqima = Jiqi. Substring (8, 5);
return Duijiqima;
}

public string Sern ()
The final serial number//m to the configuration file value
X is the serial number value
CSS to compare whether the registration code is correct
{


888888888888888888888888888888888 Get the machine code
Hasher hs = new Hasher ();

88888888888888888888888888888888888888888888888888 Get serial number
Hasher hash = new Hasher ();
Hash. Hashtext = Hs.hashgetdriveid (). ToString ();
Jiqixuelie = hash. Md5hasher ();
return Jiqixuelie;
}

}




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.