private void button2_Click_1(object sender, EventArgs e) { if (textBox2.Text != "") { SKGL.Validate valid = new SKGL.Validate(); valid.secretPhase = Environment.UserName.ToUpper() + valid.MachineCode.ToString() + "SC"; valid.Key = textBox2.Text; if (valid.IsValid) { Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SmarterCleanup"); string LicFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SmarterCleanup\\" + Environment.UserName.ToUpper() + ".lic"; using (StreamWriter sw = File.CreateText(LicFile)) { sw.WriteLine(textBox2.Text); } Application.Restart(); } else { MessageBox.Show("Invalid Key", " o_O", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } else { MessageBox.Show("Invalid Key", "^_^", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } }
static void Test2() { //1.创建key验证对象 var ValidateAKey = new Validate(); //2.设置密钥 ValidateAKey.secretPhase = "testdemo"; //3.设置要验证的key,注意,这是上面代码生成的key1内容 ValidateAKey.Key = "MFZIL-NSTBB-DLLXZ-RFHYV"; //4.直接验证是否被修改 Console.WriteLine("Key 1 验证:{0}" , ValidateAKey.IsValid); //5.检查key是否过期,false说明在有效期内 Console.WriteLine("Key 1 有效期:{0}", ValidateAKey.IsExpired); //同样验证Key2 ValidateAKey.Key = "JPVFS-BLQOQ-FLFTN-HXLFW"; //检查密钥是否被修改 Console.WriteLine("Key 2 验证:{0}", ValidateAKey.IsValid); //我电脑的实际机器码是 61125,所以结果是不一样的 Console.WriteLine("Key 2 是否和当前机器的机器码一样:{0}", ValidateAKey.IsOnRightMachine); }
private void Form1_Load_1(object sender, EventArgs e) { progressBar1.Style = ProgressBarStyle.Continuous; if (Environment.UserName.ToUpper().ToString() != "E1897") { Application.Exit(); } string uName = Environment.UserName.ToUpper().ToString(); string licFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SmarterCleanup"; if (!Directory.Exists(licFolder)) { Directory.CreateDirectory(licFolder); } // string LicFile = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\SmarterCleanup\\" + uName + ".lic"; SKGL.Validate valid = new SKGL.Validate(); if (File.Exists(LicFile)) { string tSerial = File.ReadAllText(LicFile).Trim(); valid.secretPhase = uName + valid.MachineCode.ToString() + "SC"; valid.Key = tSerial; if (valid.IsValid) { panel1.Visible = false; } else { panel1.Visible = true; textBox2.Text = uName + valid.MachineCode.ToString() + "SC"; } } else { panel1.Visible = true; textBox2.Text = uName + valid.MachineCode.ToString() + "SC"; } }
private void login_Load(object sender, EventArgs e) { string key = "";// System.Configuration.ConfigurationManager.AppSettings["serial"].Trim(); DataTable dt_key = fun.getKey(); DateTime last_date = new DateTime(); string password = "******"; //prog cc = new prog(); if (dt_key.Rows.Count > 0) { key = dt_key.Rows[0]["keys"].ToString().Trim(); } if (key == "") { labelControl3.Visible = true; simpleButton1.Visible = true; textEdit2.Visible = true; comboBox1.Visible = false; textEdit1.Visible = false; pictureBox1.Visible = false; } else { try { SKGL.Validate ValidateAKey = new SKGL.Validate(); ValidateAKey.secretPhase = password; ValidateAKey.Key = key; DateTime d = ValidateAKey.ExpireDate; if (ValidateAKey.IsValid && !ValidateAKey.IsExpired && ValidateAKey.SetTime >= ValidateAKey.DaysLeft && d > last_date) { labelControl3.Visible = false; simpleButton1.Visible = false; textEdit2.Visible = false; comboBox1.Visible = true; textEdit1.Visible = true; pictureBox1.Visible = true; if (dt_key.Rows.Count > 0) { last_date = DateTime.Parse(dt_key.Rows[0]["last_date"].ToString()); if (last_date < DateTime.Now) { fun.Update_last_day_Key(DateTime.Now); } } } else { labelControl3.Visible = true; simpleButton1.Visible = true; textEdit2.Visible = true; comboBox1.Visible = false; textEdit1.Visible = false; pictureBox1.Visible = false; } } catch (Exception bb) { labelControl3.Visible = true; simpleButton1.Visible = true; textEdit2.Visible = true; comboBox1.Visible = false; textEdit1.Visible = false; pictureBox1.Visible = false; } } // recuperer les données de société DataTable dd = new DataTable(); dd = fun.select_from_société(); if (dd.Rows.Count != 0) { raison_sociale = dd.Rows[0]["nom_societe"].ToString(); adresse = dd.Rows[0]["adresse_societe"].ToString(); fax = dd.Rows[0]["fax_societe"].ToString(); tel = dd.Rows[0]["tel_societe"].ToString(); email_sos = dd.Rows[0]["email_societe"].ToString(); test_image = dd.Rows[0]["pic_societe"].ToString(); if (test_image != "") { IMG = (Byte[])(dd.Rows[0]["logo_societe"]); MemoryStream mem = new MemoryStream(login1.IMG); pictureEdit1.Image = Image.FromStream(mem); } else { pictureEdit1.Image = null; } labelControl2.Text = raison_sociale; } this.TransparencyKey = BackColor; // requperer les pseudos DataTable zz = new DataTable(); zz = fun.combologin(); foreach (DataRow row in zz.Rows) { comboBox1.Properties.Items.Add(row["login"]); } }