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;
}
}
|
新聞熱點
疑難解答