增加注册码功能
This commit is contained in:
commit
8c38e3e12b
5 files changed
+255
-142
No files matched your search
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取硬件SN
|
||||
/// </summary>
|
||||
internal class HardwareSN
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取cpuid
|
||||
/// </summary>
|
||||
public static string GetCPUSerialNumber()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
|
||||
string cpuSerialNumber = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
cpuSerialNumber = mo["ProcessorId"].ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return cpuSerialNumber;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取主板id
|
||||
/// </summary>
|
||||
public static string GetBIOSSerialNumber()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
|
||||
string biosSerialNumber = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
biosSerialNumber = mo.GetPropertyValue("SerialNumber").ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return biosSerialNumber;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取硬盘id
|
||||
/// </summary>
|
||||
public static string GetHardDiskSerialNumber()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
|
||||
string hardDiskSerialNumber = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
hardDiskSerialNumber = mo["SerialNumber"].ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return hardDiskSerialNumber;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取网卡id
|
||||
/// </summary>
|
||||
public static string GetNetCardMACAddress()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))");
|
||||
string netCardMACAddress = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
netCardMACAddress = mo["MACAddress"].ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return netCardMACAddress;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
/// <summary>
|
||||
/// MD5加密
|
||||
/// </summary>
|
||||
internal class MD5check
|
||||
{
|
||||
/// <summary>
|
||||
/// 16位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt16(string password)
|
||||
{
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
|
||||
t2 = t2.Replace("-", "");
|
||||
return t2;
|
||||
}
|
||||
/// <summary>
|
||||
/// 32位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt32(string password)
|
||||
{
|
||||
string cl = password;
|
||||
string pwd = "";
|
||||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
|
||||
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
||||
pwd = pwd + s[i].ToString("X");
|
||||
}
|
||||
return pwd;
|
||||
}
|
||||
/// <summary>
|
||||
/// 64位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt64(string password)
|
||||
{
|
||||
string cl = password;
|
||||
//string pwd = "";
|
||||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
|
||||
return Convert.ToBase64String(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace formula_manage.UserClass
|
||||
{
|
||||
/// <summary>
|
||||
/// 字符串转数字
|
||||
/// </summary>
|
||||
internal class StrToInt
|
||||
{
|
||||
/// <summary>
|
||||
/// 十六进制字符串转十进制
|
||||
/// </summary>
|
||||
/// <param name="str">十六进制字符</param>
|
||||
/// <returns></returns>
|
||||
public static int To16Convert10(string str)
|
||||
{
|
||||
int res = 0;
|
||||
try
|
||||
{
|
||||
str = str.Trim().Replace(" ", ""); //移除空字符
|
||||
//方法1
|
||||
res = int.Parse(str, System.Globalization.NumberStyles.AllowHexSpecifier);
|
||||
//方法2
|
||||
//int r2 = System.Int32.Parse(str, System.Globalization.NumberStyles.HexNumber);
|
||||
//Console.WriteLine(r2);
|
||||
//方法3
|
||||
//int r3 = Convert.ToInt32(str, 16);
|
||||
//Console.WriteLine(r3);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
res = 0;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
+49
-142
@@ -2,6 +2,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Management;
|
||||
using System.Runtime.InteropServices;
|
||||
@@ -39,160 +40,66 @@ namespace formula_manage.Windows
|
||||
|
||||
private void Window_CDKEY(object sender, RoutedEventArgs e) //打开页面
|
||||
{
|
||||
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath); //读配置文件
|
||||
|
||||
// KEY = Configini.IniReadvalue("CDKEY", "KEY"); //读配置文件
|
||||
// SN = Configini.IniReadvalue("CDKEY", "SN");
|
||||
// 获取CPU序列号
|
||||
string cpuSerialNumber = GetCPUSerialNumber();
|
||||
string cpuSerialNumber = HardwareSN.GetCPUSerialNumber();
|
||||
// 获取主板序列号
|
||||
string biosSerialNumber = GetBIOSSerialNumber();
|
||||
string biosSerialNumber = HardwareSN.GetBIOSSerialNumber();
|
||||
// 获取硬盘序列号
|
||||
//string hardDiskSerialNumber = GetHardDiskSerialNumber();
|
||||
//string hardDiskSerialNumber = HardwareSN.GetHardDiskSerialNumber();
|
||||
// 获取网卡地址
|
||||
//string netCardMACAddress = GetNetCardMACAddress();
|
||||
//string netCardMACAddress = HardwareSN.GetNetCardMACAddress();
|
||||
|
||||
sn_id.Text = MD5Encrypt16(cpuSerialNumber+ biosSerialNumber);
|
||||
sn_id.Text = MD5check.MD5Encrypt16(cpuSerialNumber+ biosSerialNumber);//生成id基于硬件值的md5校验
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取cpuid
|
||||
/// </summary>
|
||||
public static string GetCPUSerialNumber()
|
||||
|
||||
private void Button_Click_2(object sender, RoutedEventArgs e) //cdk确认按钮
|
||||
{
|
||||
try
|
||||
string id_1;
|
||||
id_1 = sn_id.Text.Substring(5, 1) + sn_id.Text.Substring(0, 1) + sn_id.Text.Substring(4, 1) + sn_id.Text.Substring(1, 1) + sn_id.Text.Substring(3, 1) + sn_id.Text.Substring(2, 1);
|
||||
|
||||
if (id_1 == cdk.Text.Substring(0, 6))
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_Processor");
|
||||
string cpuSerialNumber = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
if (CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(cdk.Text.Substring(0, 12)), true) == cdk.Text.Substring(12, 4)) //校验key的crc校验值
|
||||
{
|
||||
cpuSerialNumber = mo["ProcessorId"].ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return cpuSerialNumber;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取主板id
|
||||
/// </summary>
|
||||
public static string GetBIOSSerialNumber()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
|
||||
string biosSerialNumber = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
biosSerialNumber = mo.GetPropertyValue("SerialNumber").ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return biosSerialNumber;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取硬盘id
|
||||
/// </summary>
|
||||
public static string GetHardDiskSerialNumber()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia");
|
||||
string hardDiskSerialNumber = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
hardDiskSerialNumber = mo["SerialNumber"].ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return hardDiskSerialNumber;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取网卡id
|
||||
/// </summary>
|
||||
public static string GetNetCardMACAddress()
|
||||
{
|
||||
try
|
||||
{
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter WHERE ((MACAddress Is Not NULL) AND (Manufacturer <> 'Microsoft'))");
|
||||
string netCardMACAddress = "";
|
||||
foreach (ManagementObject mo in searcher.Get())
|
||||
{
|
||||
netCardMACAddress = mo["MACAddress"].ToString().Trim();
|
||||
break;
|
||||
}
|
||||
return netCardMACAddress;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 16位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt16(string password)
|
||||
{
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
string t2 = BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(password)), 4, 8);
|
||||
t2 = t2.Replace("-", "");
|
||||
return t2;
|
||||
}
|
||||
/// <summary>
|
||||
/// 32位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt32(string password)
|
||||
{
|
||||
string cl = password;
|
||||
string pwd = "";
|
||||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
|
||||
// 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
|
||||
for (int i = 0; i < s.Length; i++)
|
||||
{
|
||||
// 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
|
||||
pwd = pwd + s[i].ToString("X");
|
||||
}
|
||||
return pwd;
|
||||
}
|
||||
/// <summary>
|
||||
/// 64位MD5加密
|
||||
/// </summary>
|
||||
/// <param name="password"></param>
|
||||
/// <returns></returns>
|
||||
public static string MD5Encrypt64(string password)
|
||||
{
|
||||
string cl = password;
|
||||
//string pwd = "";
|
||||
MD5 md5 = MD5.Create(); //实例化一个md5对像
|
||||
// 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择
|
||||
byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
|
||||
return Convert.ToBase64String(s);
|
||||
}
|
||||
string Y = (2255 - StrToInt.To16Convert10(cdk.Text.Substring(6, 2))).ToString();
|
||||
string M = (255 - StrToInt.To16Convert10(cdk.Text.Substring(8, 2))).ToString();
|
||||
string D = (255 - StrToInt.To16Convert10(cdk.Text.Substring(10, 2))).ToString();
|
||||
|
||||
string YY = DateTime.Now.ToString("yyyy");
|
||||
string MM = DateTime.Now.ToString("MM");
|
||||
string DD = DateTime.Now.ToString("dd");
|
||||
|
||||
private void Button_Click_2(object sender, RoutedEventArgs e)
|
||||
{
|
||||
string t;
|
||||
t = sn_id.Text.Substring(0,6);
|
||||
|
||||
cdk.Text = t +"240102" + CRCcheck16.ToCRC16(CRCcheck16.StringToHexByte(t+ "240102"),true);
|
||||
if (string.Compare(Y, YY) >= 0)
|
||||
{
|
||||
if (string.Compare(M, MM) >= 0)
|
||||
{
|
||||
if (string.Compare(D, DD) >= 0)
|
||||
{
|
||||
System.Windows.MessageBox.Show("CDKEY:OK");
|
||||
sn_time.Text = "CDkeyDueTime: " + Y + "-" + M + "-" + D;
|
||||
|
||||
UserClass.IniFile.IniFiles Configini = new UserClass.IniFile.IniFiles(INIPath);
|
||||
Configini.IniWritevalue("SN", " SN1", id_1);
|
||||
Configini.IniWritevalue("SN", " SN2", cdk.Text.Substring(6, 2));
|
||||
Configini.IniWritevalue("SN", " SN3", cdk.Text.Substring(8, 2));
|
||||
Configini.IniWritevalue("SN", " SN4", cdk.Text.Substring(10, 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("CDKEY:overdue");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("CDKEY:overdue");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Windows.MessageBox.Show("CDKEY:overdue");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -217,10 +217,13 @@
|
||||
<Compile Include="SQLModels\STUFF_Product.cs" />
|
||||
<Compile Include="UserClass\CRCcheck16.cs" />
|
||||
<Compile Include="UserClass\DataGridHelper.cs" />
|
||||
<Compile Include="UserClass\HardwareSN.cs" />
|
||||
<Compile Include="UserClass\IniFile.cs" />
|
||||
<Compile Include="UserClass\MD5check.cs" />
|
||||
<Compile Include="UserClass\PressKey.cs" />
|
||||
<Compile Include="UserClass\DataTableForToObservableCollection.cs" />
|
||||
<Compile Include="UserClass\PrintHelper.cs" />
|
||||
<Compile Include="UserClass\StrToInt.cs" />
|
||||
<Compile Include="UserClass\UserPrint.cs" />
|
||||
<Compile Include="ViewModel\RECIPEViewModel.cs" />
|
||||
<Compile Include="ViewModel\MainWindowViewModel.cs" />
|
||||
|
||||
Reference in new issue
Block a user