C#程式怎麼做註冊碼?

來源:互聯網
上載者:User
程式

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>
/// cs 的摘要說明
/// </summary>
///
namespace cs
{
public class cs
{
//判斷序號
public bool css()
//m為設定檔值
//x為序號值
//css進行比較該註冊碼是否正確
{
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為寫入的參數
//用於註冊碼不正確的時候使用
{
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)
//寫入設定檔資訊
//path是請求的虛擬路徑
//x要修改的值
{

Configuration config = WebConfigurationManager.OpenWebConfiguration(path);

config.AppSettings.Settings.Clear();
// string m = ConfigurationManager.AppSettings.Get("message");
config.AppSettings.Settings.Add("message", x);
config.Save();

}


}
}
 
 
Top
 
  回複人:wuda8(c# asp.net 2.0部落格) ( ) 信譽:93 2006-11-1 15:37:43 得分: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>
/// Hasher 的摘要說明
/// </summary>
///
namespace Hasher
{

public class Hasher
{

// private byte[] _HashKey; //雜湊金鑰儲存區變數
public string _HashText; //待加密的字串
// public Hasher()
// {
// }


// 需要產生加密雜湊的字串
public string HashText
{
set
{
_HashText = value;
}
get
{
return _HashText;
}
}

/// 使用MD5CryptoServiceProvider類產生雜湊值。不需要提供密鑰。
/// </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); //返回長度為25位元組字串
}


//擷取cpu序號
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
//擷取硬碟序號
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;
///得到機器碼
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()
//最終的序號 //m為設定檔值
//x為序號值
//css進行比較該註冊碼是否正確
{


//888888888888888888888888888888888擷取機器碼
Hasher hs = new Hasher();

//88888888888888888888888888888888888888888888888888擷取序號
Hasher hash = new Hasher();
hash.HashText = hs.hashGetDriveID().ToString ();
jiqixuelie = hash.MD5Hasher();
return jiqixuelie;
}

}
 
 



相關文章

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。