对于一个商业软件来说,授权码这个功能必不可少。我这里采用CPU序列号加硬盘标识来判断是否授权。完整代码如下:

using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;namespace KeyManager
{public partial class FrmShouQuan : Form{public FrmShouQuan(){InitializeComponent();}/// <summary>/// 获取CPU的参数/// </summary>/// <returns></returns>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;}/// <summary>/// 获取硬盘的参数/// </summary>/// <returns></returns>public string GetDiskVolumeSerialNumber(){ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"c:\"");disk.Get();return disk.GetPropertyValue("VolumeSerialNumber").ToString();}/// <summary>/// 生成机器码,就是CPU参数加上硬盘参数/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button1_Click(object sender, EventArgs e){txtMachineInfo.Text = getCpu() + GetDiskVolumeSerialNumber();//获得24位Cpu和硬盘序列号}public int[] intCode = new int[127];//用于存密钥public void setIntCode(){for (int i = 1; i < intCode.Length; i++){intCode[i] = i % 10;}}public int[] intNumber = new int[25];//用于存机器码的Ascii值public char[] Charcode = new char[25];//存储机器码字//生成注册码private void button2_Click(object sender, EventArgs e){if (txtMachineInfo.Text != ""){txtRegistText.Text = GetResistText(txtMachineInfo.Text);}else{ MessageBox.Show("请选生成机器码", "注册提示"); }}/// <summary>/// 根据机器码获取注册码/// </summary>/// <param name="machineText"></param>/// <returns></returns>private string GetResistText(string machineText){//把机器码存入数组中setIntCode();//初始化127位数组for (int i = 1; i < Charcode.Length; i++)//把机器码存入数组中{Charcode[i] = Convert.ToChar(machineText.Substring(i - 1, 1));}for (int j = 1; j < intNumber.Length; j++)//把字符的ASCII值存入一个整数组中。{intNumber[j] = intCode[Convert.ToInt32(Charcode[j])] + Convert.ToInt32(Charcode[j]);}string strAsciiName = null;//用于存储机器码for (int j = 1; j < intNumber.Length; j++){if (intNumber[j] >= 48 && intNumber[j] <= 57)//判断字符ASCII值是否0-9之间{strAsciiName += Convert.ToChar(intNumber[j]).ToString();}else if (intNumber[j] >= 65 && intNumber[j] <= 90)//判断字符ASCII值是否A-Z之间{strAsciiName += Convert.ToChar(intNumber[j]).ToString();}else if (intNumber[j] >= 97 && intNumber[j] <= 122)//判断字符ASCII值是否a-z之间{strAsciiName += Convert.ToChar(intNumber[j]).ToString();}else//判断字符ASCII值不在以上范围内{if (intNumber[j] > 122)//判断字符ASCII值是否大于z{ strAsciiName += Convert.ToChar(intNumber[j] - 10).ToString(); }else{strAsciiName += Convert.ToChar(intNumber[j] - 9).ToString();}}}return strAsciiName;}private void btnRegist_Click(object sender, EventArgs e){if (txtRegistText.Text != ""){if (textBox1.Text.TrimEnd().Equals(txtRegistText.Text.TrimEnd())){//这里需要将机器码和注册码保存到数据库或注册表中,以便以后校验(推荐保存到数据库中,这样不怕重装系统)MessageBox.Show("注册成功");}else{MessageBox.Show("注册码输入错误");}}else { MessageBox.Show("请生成注册码", "注册提示"); }}/// <summary>/// 验证是否已经激活软件/// </summary>/// <param name="sender"></param>/// <param name="e"></param>private void button4_Click(object sender, EventArgs e){//这里重新生成机器码和注册码,与数据库中进行对比。只要有一个参数不一致,就是未激活(此处省略两万行代码)}}
}

设计文件的代码:

namespace KeyManager
{partial class FrmShouQuan{/// <summary>/// Required designer variable./// </summary>private System.ComponentModel.IContainer components = null;/// <summary>/// Clean up any resources being used./// </summary>/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>protected override void Dispose(bool disposing){if (disposing && (components != null)){components.Dispose();}base.Dispose(disposing);}#region Windows Form Designer generated code/// <summary>/// Required method for Designer support - do not modify/// the contents of this method with the code editor./// </summary>private void InitializeComponent(){this.textBox1 = new System.Windows.Forms.TextBox();this.button1 = new System.Windows.Forms.Button();this.button2 = new System.Windows.Forms.Button();this.button3 = new System.Windows.Forms.Button();this.txtRegistText = new System.Windows.Forms.TextBox();this.txtMachineInfo = new System.Windows.Forms.TextBox();this.button4 = new System.Windows.Forms.Button();this.label1 = new System.Windows.Forms.Label();this.label2 = new System.Windows.Forms.Label();this.label3 = new System.Windows.Forms.Label();this.textBox2 = new System.Windows.Forms.TextBox();this.label4 = new System.Windows.Forms.Label();this.textBox3 = new System.Windows.Forms.TextBox();this.label5 = new System.Windows.Forms.Label();this.SuspendLayout();// // textBox1// this.textBox1.Location = new System.Drawing.Point(238, 126);this.textBox1.Name = "textBox1";this.textBox1.Size = new System.Drawing.Size(278, 25);this.textBox1.TabIndex = 1;// // button1// this.button1.Location = new System.Drawing.Point(72, 272);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(114, 32);this.button1.TabIndex = 2;this.button1.Text = "获取硬件信息";this.button1.UseVisualStyleBackColor = true;this.button1.Click += new System.EventHandler(this.button1_Click);// // button2// this.button2.Location = new System.Drawing.Point(228, 272);this.button2.Name = "button2";this.button2.Size = new System.Drawing.Size(98, 32);this.button2.TabIndex = 2;this.button2.Text = "生成注册码";this.button2.UseVisualStyleBackColor = true;this.button2.Click += new System.EventHandler(this.button2_Click);// // button3// this.button3.Location = new System.Drawing.Point(368, 272);this.button3.Name = "button3";this.button3.Size = new System.Drawing.Size(75, 32);this.button3.TabIndex = 2;this.button3.Text = "注册";this.button3.UseVisualStyleBackColor = true;this.button3.Click += new System.EventHandler(this.btnRegist_Click);// // txtRegistText// this.txtRegistText.Location = new System.Drawing.Point(238, 89);this.txtRegistText.Name = "txtRegistText";this.txtRegistText.Size = new System.Drawing.Size(278, 25);this.txtRegistText.TabIndex = 1;// // txtMachineInfo// this.txtMachineInfo.Location = new System.Drawing.Point(238, 52);this.txtMachineInfo.Name = "txtMachineInfo";this.txtMachineInfo.Size = new System.Drawing.Size(278, 25);this.txtMachineInfo.TabIndex = 1;// // button4// this.button4.Location = new System.Drawing.Point(485, 272);this.button4.Name = "button4";this.button4.Size = new System.Drawing.Size(118, 32);this.button4.TabIndex = 2;this.button4.Text = "检查是否注册";this.button4.UseVisualStyleBackColor = true;this.button4.Click += new System.EventHandler(this.button4_Click);// // label1// this.label1.AutoSize = true;this.label1.Location = new System.Drawing.Point(159, 52);this.label1.Name = "label1";this.label1.Size = new System.Drawing.Size(67, 15);this.label1.TabIndex = 3;this.label1.Text = "机器码:";// // label2// this.label2.AutoSize = true;this.label2.Location = new System.Drawing.Point(159, 90);this.label2.Name = "label2";this.label2.Size = new System.Drawing.Size(67, 15);this.label2.TabIndex = 3;this.label2.Text = "授权码:";// // label3// this.label3.AutoSize = true;this.label3.Location = new System.Drawing.Point(114, 128);this.label3.Name = "label3";this.label3.Size = new System.Drawing.Size(112, 15);this.label3.TabIndex = 3;this.label3.Text = "请输入授权码:";// // textBox2// this.textBox2.Location = new System.Drawing.Point(238, 163);this.textBox2.Name = "textBox2";this.textBox2.Size = new System.Drawing.Size(278, 25);this.textBox2.TabIndex = 1;this.textBox2.Visible = false;// // label4// this.label4.AutoSize = true;this.label4.Location = new System.Drawing.Point(99, 166);this.label4.Name = "label4";this.label4.Size = new System.Drawing.Size(127, 15);this.label4.TabIndex = 3;this.label4.Text = "请输入起始日期:";this.label4.Visible = false;// // textBox3// this.textBox3.Location = new System.Drawing.Point(238, 200);this.textBox3.Name = "textBox3";this.textBox3.Size = new System.Drawing.Size(278, 25);this.textBox3.TabIndex = 1;this.textBox3.Visible = false;// // label5// this.label5.AutoSize = true;this.label5.Location = new System.Drawing.Point(99, 203);this.label5.Name = "label5";this.label5.Size = new System.Drawing.Size(127, 15);this.label5.TabIndex = 3;this.label5.Text = "请输入有效天数:";this.label5.Visible = false;// // FrmShouQuan// this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 15F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(688, 339);this.Controls.Add(this.label5);this.Controls.Add(this.label4);this.Controls.Add(this.label3);this.Controls.Add(this.label2);this.Controls.Add(this.label1);this.Controls.Add(this.button4);this.Controls.Add(this.button3);this.Controls.Add(this.button2);this.Controls.Add(this.button1);this.Controls.Add(this.txtMachineInfo);this.Controls.Add(this.txtRegistText);this.Controls.Add(this.textBox3);this.Controls.Add(this.textBox2);this.Controls.Add(this.textBox1);this.Name = "FrmShouQuan";this.Text = "FrmShouQuan";this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.Button button1;private System.Windows.Forms.Button button2;private System.Windows.Forms.Button button3;private System.Windows.Forms.TextBox txtRegistText;private System.Windows.Forms.TextBox txtMachineInfo;private System.Windows.Forms.Button button4;private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;private System.Windows.Forms.Label label3;private System.Windows.Forms.TextBox textBox2;private System.Windows.Forms.Label label4;private System.Windows.Forms.TextBox textBox3;private System.Windows.Forms.Label label5;}
}

运行效果:

C# 实现软件授权码的功能相关推荐

  1. 企业网上下单订货管理软件源码搭建功能介绍|移讯云订货通订单管理系统

    网上下单订货管理软件源码搭建功能介绍|移讯云订货通订单管理系统 一:系统概述和用途 系统基于网络,实现厂家和代理商批发商通过网络下单订货功能. 什么是移讯云订货通.什么是企业订货管理系统. 是一款针对 ...

  2. 软件授权码方案(附Python示例代码)

    思路: 软件安装后,运行软件时,通过电脑机器码的唯一性实现授权码的唯一性.(机器码:由cpu序列号.硬盘序列号.mac地址.主板序列号组成的字符串截取部分字符) 方案: 1.运行软件,检测注册文件,若 ...

  3. 国家商用密码(2)基于SM2的软件授权码生成及校验

    将公开密钥算法作为软件注册算法的好处是Cracker很难通过跟踪验证算法得到注册机.下面,将介绍使用SM2国密算法进行软件注册的方法. 生成授权码 选择SM2椭圆曲线参数(P,a,b,N,Gx,Gy) ...

  4. H5类似易企秀/编辑器/页面制作/开发/生成工具/软件/源码/授权

    代码地址如下: http://www.demodashi.com/demo/14960.html 项目简介 H5DS (HTML5 Design software) 这是一款基于WEB的 H5制作工具 ...

  5. python 做软件授权代理_软件提卡+授权API+代理系统三合一网站源码(开源)

    功能说明: 此网站系统是集成了以下多种功能:软件授权验证系统通过API接口进行验证使用者是否拥有授权. 软件可设置使用时间,如使用者没有授权,将手动添加试用授权.网站手动生成卡密系统内部对接授权系统q ...

  6. c语言 网络授权 破解,[授权码]苹果Mac平台C程序的防盗版功能和License授权管理...

    PP商业软件授权平台可以帮助软件工程师实现这样的功能:比如相同的一份程序,A.B.C三客户获得的是不同类型和级别的授权码,A客户只能在2颗及以下CPU.16G及以下内存.1TB及以下硬盘的Linux服 ...

  7. 免服务器软件库源码实现超级管理动态发布会员系统卡密系统充值对接卡密网软件发布板块后台功能 软件商店1.3.1

    简介: 免服务器软件库源码(免服务器软件库源码是什么?)当前完成功能用户登录用户注册软件投稿(可使用链接上传或者服务器存储) 动态发布会员系统卡密系统充值对接卡密网软件发布板块后台功能如下软件管理分类 ...

  8. Linux环境使用授权码实现软件授权

    Linux服务器,想实现软件加密授权的方式有:加密锁,软锁(账号及授权码),云锁. 三种不同的授权方式使用的区别. 加密锁:可以适用完全离线的环境,做限时限次等. 软锁:分为账号软锁及授权码,离线及在 ...

  9. 直播软件源码,实现一个简单的直播功能

    概述 一直好奇直播软件源码这个东东是如何实现的,譬如音视频流是如何采集的? 音视频流是如何推送到订阅方 ? 如何支撑上万级.百万级用户同时观看直播 ? 功能设计 如上图所示为直播软件源码 Demo 实 ...

最新文章

  1. Android 属性动画(Property Animation) ObjectAnimator的介绍
  2. 27.5. PROCEDURE ANALYSE()
  3. 动态生成能够局部刷新的验证码【AJAX技术】---看了不懂赔你钱
  4. cdn刷新api_闲话 CDN
  5. 【Java集合源码剖析】Hashtable源码剖析
  6. oracle控制文件修复,oracle控制文件的损坏或完全丢失的恢复办法
  7. 2017尼毕鲁笔试算法题
  8. 北斗有 35 颗卫星,而 GPS 有 24 颗卫星,为什么二者数量不同?
  9. 埃拉托斯特尼筛法 快速查找素数
  10. java每过一段时间执行一次代码(方法)
  11. python中datetime函数怎么获得当年年份_Python 日期和时间函数使用指南
  12. 柳暗花明 | 海归小硕的求职之路
  13. ORA-01017解决方案
  14. Hibernate二级缓存适用场景
  15. Java购票系统实训总结_Java 购票系统实现
  16. PDCA理念融入软件测试
  17. 用Unity的GetSpectrumData方法识别钢琴曲中的钢琴琴键
  18. 开发一个套crm系统软件需要多少钱
  19. 解决面部毛孔粗大的7个小窍门 - 健康程序员,至尚生活!
  20. marker 上的气泡 callout属性设置无效

热门文章

  1. 【干货】线上线下活动策划详细方案.pdf(附下载链接)
  2. SAP Marketing Cloud 功能概述(三)
  3. 2018_2_3_Boolean Expressions_栈_模拟
  4. mysql 的 虚拟表(DUAL)的介绍及使用场景---条件插入insert
  5. HyperLPR车牌识别技术算法之车牌粗定位与训练
  6. 明翰数据结构与算法笔记V0.8(持续更新)
  7. Vim 大小写切换快捷键
  8. 审计大数据综合分析采集管理系统软件平台
  9. 统计学:离散型和连续型随机变量的概率分布
  10. 荣耀v40pro+参数配置 荣耀v40pro+价格