asp.net(c#) 制作注册码程序

1、定义CS类 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();

        }
    }
}
定义Hasher类

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;
        }
    }
}
下面这些注册码是在配置文件里写的

<appSettings>
  <clear />
  <add key="message" value="gSHtZ6yh/QegTbH8/iTaIg==" />
</appSettings>

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
ASP.NET 手机验证注册的实现方式与普通注册类似,只需要在注册的过程中添加手机验证即可。以下是一个简单的 ASP.NET 手机验证注册的示例: 1. 创建一个 ASP.NET Web 应用程序,按照上述步骤创建一个“Register.aspx”页面和“Register.aspx.cs”文件。 2. 在“Register.aspx”页面中添加一个“PhoneCode”文本框和一个“GetCode”按钮,用于获取手机验证码。代码如下: ```html <label for="txtPhone">Phone:</label> <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox> <label for="txtPhoneCode">Phone Code:</label> <asp:TextBox ID="txtPhoneCode" runat="server"></asp:TextBox> <asp:Button ID="btnGetCode" runat="server" Text="Get Code" OnClick="btnGetCode_Click" /> ``` 3. 在“Register.aspx.cs”文件中添加一个“btnGetCode_Click”事件处理程序,用于发送手机验证码。代码如下: ```c# protected void btnGetCode_Click(object sender, EventArgs e) { string phone = txtPhone.Text; // 在这里添加发送手机验证码的代码 } ``` 4. 在“Register.aspx”页面中添加一个“Register”按钮,用于提交注册信息。代码如下: ```html <asp:Button ID="btnRegister" runat="server" Text="Register" OnClick="btnRegister_Click" /> ``` 5. 在“Register.aspx.cs”文件中添加一个“btnRegister_Click”事件处理程序,用于验证手机验证码并注册用户。代码如下: ```c# protected void btnRegister_Click(object sender, EventArgs e) { string name = txtName.Text; string phone = txtPhone.Text; string phoneCode = txtPhoneCode.Text; // 在这里添加验证手机验证码并注册用户的代码 } ``` 6. 在“验证手机验证码并注册用户”的代码中,您可以使用第三方短信服务提供商发送手机验证码,并将验证码存储在 Session 中。然后在用户提交注册信息时,您可以比较用户输入的验证码和 Session 中存储的验证码是否一致,以确保用户输入的手机号码属于本人。如果验证码一致,您可以将用户信息存储到数据库或其他存储介质中。 7. 运行应用程序,并在浏览器中打开“Register.aspx”页面。在“Name”和“Phone”字段中输入相应的值,并单击“Get Code”按钮。在“btnGetCode_Click”事件处理程序中,您可以添加发送手机验证码的代码。然后输入收到的验证码,并单击“Register”按钮。在“btnRegister_Click”事件处理程序中,您可以添加验证手机验证码并注册用户的代码。 以上是一个简单的 ASP.NET 手机验证注册示例,您可以将其扩展为满足您特定需求的应用程序

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值