C#写了一个简单的注册机制 每次生成的注册码都一样 求解

qq_29575049 qq_29575049 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)
{
Random rd = new Random();
int num1 = rd.Next(100000, 999999);
int num2 = rd.Next(100000, 999999);
textBox1.Text = "" + num1 + getCpu() + num2;


string apppath = Environment.CurrentDirectory;
string path = apppath + @"\key.txt";
string str;
StreamReader sr = new StreamReader(path, false);
try
{

str = sr.ReadLine().ToString();
sr.Close();
this.textBox2.Text = str;///读取
}
catch
{

sr.Close();
}
// textBox2.Text = line;




}

public string getCpu()
{
string strCpu = null;
ManagementClass myCpu = new ManagementClass("win32_Processor");
ManagementObjectCollection myCpuConnection = myCpu.GetInstances();
foreach (ManagementObject myObject in myCpuConnection)
{
strCpu = myObject.Properties["Processorid"].Value.ToString();
break;
}
return strCpu;
}

private void button1_Click(object sender, EventArgs e)
{
string str1 = textBox1.Text.Substring(6, 16);
var md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(str1)), 4, 8);
t2 = t2.Replace("-", "");

if (textBox2.Text == t2)
{
StreamWriter sw = new StreamWriter("key.txt", false);
sw.Write(textBox2.Text);

sw.Flush();
sw.Close();
Form1 f1 = new Form1();
f1.Show();
this.Hide();


}
else
{
if (textBox2.Text != "")
{
MessageBox.Show("注册码错误!");
}
}
...全文

相关推荐

评论 8
收藏 已收藏
分享
返回顶部
qq_29575049
C# 111,128 成员 642,537 内容