如何获取许可证密钥? [英] How to get the license key?
本文介绍了如何获取许可证密钥?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Windows应用程序中获取许可证密钥。我需要2PHXF-9PBDW-D3WWY-CPDKD-XG87V这种格式。请帮帮我......
i试过这个代码
private void btn_License_Click( object sender, EventArgs e)
{
Random ran = new Random();
textBox1.Text = + ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ _ + ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ _ + ran.Next( 0 , 9 )+ ran.Next( 0 , 9 ) + ran.Next( 0 , 9 )+ ran.Next( 0 , 9 )+ ran.Next( 0 , 9 跨度>);
}
解决方案
我的解决方案是:
私人static Random rd = new Random((int)DateTime.Now.Ticks);
private void btn_License_Click( object sender,EventArgs e)
{
string str1 = GeneratePassword( 5 , 0 );
string str2 = GeneratePassword( 5 , 0 跨度>);
string str3 = GeneratePassword( 5 , 0 跨度>);
string str4 = GeneratePassword( 5 , 0 跨度>);
string str5 = GeneratePassword( 5 , 0 跨度>);
textBox1.Text = str1 + - + str2 + - + str3 + - + str4 + - + str5;
}
public static string GeneratePassword( int Lenght, int NonAlphaNumericChars)
{
string allowedChars = ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;
string allowedNonAlphaNum = !@#
%^&安培; *()_- + = [{]};:其中;> | ./?\"跨度>;
// Random rd = new Random((int)DateTime.Now.Ticks);
if (NonAlphaNumericChars > Lenght || Lenght < = 0 || NonAlphaNumericChars < 0 )
throw new ArgumentOutOfRangeException();
char [] pass = new 炭跨度> [Lenght];
int [] pos = new int < /跨度> [Lenght];
int i = 0 ,j = 0 ,temp = 0 ;
bool flag = false ;
// 随机输入字符串传递的pos数组的位置值
while (i < 长度 - 1 )
{
j = 0 ;
flag = false ;
temp = rd.Next( 0 ,Lenght);
for (j = 0 ; j < 长度; j ++)
如果(temp == pos [j])
{
flag = true ;
j =长度;
}
if (!flag)
{
pos [i] = temp;
i ++;
}
}
// 随机AlphaNumericChars
for (i = 0 ; i < Lenght - NonAlphaNumericChars; i ++)
pass [i] = allowedChars [rd.Next( 0 ,allowedChars.Length)];
// 随机NonAlphaNumericChars
for (i = Lenght - NonAlphaNumericChars; i < Lenght; i ++)
pass [i] = allowedNonAlphaNum [rd .Next( 0 ,allowedNonAlphaNum.Length)];
// 按照数据位置的pos数组设置排序数组值
char [] sorted = new char 跨度> [Lenght];
for (i = 0 ; i < ; 长度; i ++)
sorted [i] = pass [pos [i]];
string Pass = new 串跨度>(排序);
返回通过;
}
结果是:Y4CDQ-GAIW5-VIWE1-0EFN6-C5Z7H
这是C#代码。只需点击按钮,您将获得不同的许可证密钥
使用System;
使用System.Collections.Generic;使用System.ComponentModel
;
使用System.Data;使用System.Drawing
;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
命名空间WindowsFormsApplication1
{
public partial class Form1:Form
{
Random random = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender,EventArgs e)
{
string s1 = RandomString();
string s2 = RandomString();
string s3 = RandomString();
string s4 = RandomString();
string s5 = RandomString();
textBox1.Text = s1 + - + s2 + - + s3 + - + s4 + - + s5;
}
公共字符串RandomString()
{
string input =ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;
StringBuilder builder = new StringBuilder();
char ch;
for(int i = 0; i< 5; i ++)
{
ch = input [random.Next(0,input.Length)];
builder.Append(ch);
}
返回builder.ToString();
}
}
}
退房并告知我们是否有帮助
How to get the license key in windows application. And i need 2PHXF-9PBDW-D3WWY-CPDKD-XG87V this format. Please help me....
i have tried this code
private void btn_License_Click(object sender, EventArgs e)
{
Random ran = new Random();
textBox1.Text = "" + ran.Next(0, 9) + ran.Next(0,9) + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9) + "_" + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9) + "_" + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9) + ran.Next(0, 9);
}
解决方案
My Soltion is:
private static Random rd = new Random((int)DateTime.Now.Ticks);
private void btn_License_Click(object sender, EventArgs e) { string str1 = GeneratePassword(5, 0); string str2 = GeneratePassword(5, 0); string str3 = GeneratePassword(5, 0); string str4 = GeneratePassword(5, 0); string str5 = GeneratePassword(5, 0); textBox1.Text = str1 + "-" + str2 + "-" + str3 + "-" + str4 + "-" + str5;
} public static string GeneratePassword(int Lenght, int NonAlphaNumericChars) { string allowedChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; string allowedNonAlphaNum = "!@#
%^&*()_-+=[{]};:<>|./?"; //Random rd= new Random((int)DateTime.Now.Ticks); if (NonAlphaNumericChars > Lenght || Lenght <= 0 || NonAlphaNumericChars < 0) throw new ArgumentOutOfRangeException(); char[] pass = new char[Lenght]; int[] pos = new int[Lenght]; int i = 0, j = 0, temp = 0; bool flag = false; //Random the position values of the pos array for the string Pass while (i < Lenght - 1) { j = 0; flag = false; temp = rd.Next(0, Lenght); for (j = 0; j < Lenght; j++) if (temp == pos[j]) { flag = true; j = Lenght; } if (!flag) { pos[i] = temp; i++; } } //Random the AlphaNumericChars for (i = 0; i < Lenght - NonAlphaNumericChars; i++) pass[i] = allowedChars[rd.Next(0, allowedChars.Length)]; //Random the NonAlphaNumericChars for (i = Lenght - NonAlphaNumericChars; i < Lenght; i++) pass[i] = allowedNonAlphaNum[rd.Next(0, allowedNonAlphaNum.Length)]; //Set the sorted array values by the pos array for the rigth posistion char[] sorted = new char[Lenght]; for (i = 0; i < Lenght; i++) sorted[i] = pass[pos[i]]; string Pass = new String(sorted); return Pass; }
Result is:Y4CDQ-GAIW5-VIWE1-0EFN6-C5Z7H
Here is the C# code.Just click on button and you will get different license keys
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { Random random = new Random(); public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string s1 = RandomString(); string s2 = RandomString(); string s3 = RandomString(); string s4 = RandomString(); string s5 = RandomString(); textBox1.Text = s1+" - "+s2+" - "+s3+" - "+s4+" - "+s5; } public string RandomString() { string input = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; StringBuilder builder = new StringBuilder(); char ch; for (int i = 0; i < 5; i++) { ch = input[random.Next(0, input.Length)]; builder.Append(ch); } return builder.ToString(); } } }
Check out and let me know if it helped
这篇关于如何获取许可证密钥?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文