首页 > 开发 > 综合 > 正文

C#程序怎么做注册码?

2024-07-21 02:26:05
字体:
来源:转载
供稿:网友
  • 本文来源于网页设计爱好者web开发社区http://www.html.org.cn收集整理,欢迎访问。
  • 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;
    }

    }
     
     

    发表评论 共有条评论
    用户名: 密码:
    验证码: 匿名发表