private void Verify() { try { var computerData = new ComputerData(); var skey = "10/06/20"; if (!computerData.IsOkComputer(skey,_vitrola.CurrentDirectory)) { if (computerData.SameUser) Close(); Random random = new Random(); var insertlicence = new Licence(random.Next(10000, 99999).ToString(), false); insertlicence.ShowDialog(); if (!computerData.InsertLicence(insertlicence.GiveMeRandom(), insertlicence.GiveMeLicence(), skey, false)) { MessageBox.Show( "Contactar al Proveedor", "Licencia Inválida"); Close(); } } } catch { MessageBox.Show("Problema al identificar el origen del programa", "Licencia Inválida"); Close(); } }
/// <summary> /// Metodo que verifica si el software puede correr en la pc /// </summary> /// <param name="skeyp"></param> /// <returns></returns> public bool IsOkComputer(string skeyp,string currentDir) { var skey = skeyp.Replace('/', '3'); if (!File.Exists(currentDir+"\\lic.lot")) return false; try { security = new Security(); GCHandle gch = GCHandle.Alloc(skey, GCHandleType.Pinned); security.DecryptFile(currentDir+"\\lic.lot",currentDir+ "\\tempL", skey); gch.Free(); var lista = File.ReadAllText(currentDir+"\\tempL").Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries); File.Delete(currentDir+"\\tempL"); var user = lista[0]; var number = lista[1].Remove(0, 2); var otherNumbers = lista[2].Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList(); var mac = new List<string>(); if (lista.Length == 4) mac = lista[3].Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToList(); //empezamos a verificar var vUser = UserName(); var vNumberHdd = NumberHdd(); var vOtherNumberHdd = OtherNumberHdd(); var vMacsAddres = MacsAddres();//puede no estar habilitada if (otherNumbers.Count == 0 && vNumberHdd == number) { var list = new List<string>(); //list.Add(GetProcessorID()); list.Add("*"); list.Add(vUser + "*"); list.Add(vNumberHdd + "*"); list.AddRange(vOtherNumberHdd); list.Add("*"); list.AddRange(vMacsAddres); File.WriteAllLines("temp3", list); skey = skey.Replace('/', '3'); GCHandle gch1 = GCHandle.Alloc(skey, GCHandleType.Pinned); security.EncryptFile("temp3", "lic.lot", skey); gch1.Free(); File.Delete("temp3"); return true; } //if (number != vNumberHdd) // MessageBox.Show("Upss...Tenga en cuenta que el programa " + // "se ha ejecutado en una dirección diferente y necesita " + // "que su archivo de licencia esté en la misma dirección!"); foreach (var otherNumber in otherNumbers) { if (vOtherNumberHdd.Contains(otherNumber)) { var list = new List<string>(); //list.Add(GetProcessorID()); list.Add("*"); list.Add(vUser + "*"); list.Add(vNumberHdd + "*"); list.AddRange(vOtherNumberHdd); list.Add("*"); list.AddRange(vMacsAddres); File.WriteAllLines(currentDir+"\\temp3", list); skey = skey.Replace('/', '3'); GCHandle gch1 = GCHandle.Alloc(skey, GCHandleType.Pinned); security.EncryptFile(currentDir+"\\temp3", currentDir+"\\lic.lot", skey); gch1.Free(); File.Delete(currentDir+"\\temp3"); return true; //es el mismo disco duro } } if (vMacsAddres.Count != 0) { foreach (var m in mac) { if (vMacsAddres.Contains(m)) { var list = new List<string>(); //list.Add(GetProcessorID()); list.Add("*"); list.Add(vUser + "*"); list.Add(vNumberHdd + "*"); list.AddRange(vOtherNumberHdd); list.Add("*"); list.AddRange(vMacsAddres); File.WriteAllLines(currentDir+"\\temp3", list); skey = skey.Replace('/', '3'); GCHandle gch2 = GCHandle.Alloc(skey, GCHandleType.Pinned); security.EncryptFile(currentDir+"\\temp3", currentDir + "\\lic.lot", skey); gch2.Free(); File.Delete(currentDir+"\\temp3"); return true; //tiene la misma tarjeta de red } } } if (vUser == user)//es el mismo usuario porque ha cambiado de pc { MessageBox.Show("Ha copiado el programa en otra PC." + " Contactar a: 53392127, Email: [email protected]/[email protected]/@yahoo.com/@hotmail.com" + " para que reciba otra licencia"); Random random = new Random(); var insertlicence = new Licence(random.Next(10000, 99999).ToString(), false); insertlicence.ShowDialog(); if (!InsertLicence(insertlicence.GiveMeRandom(), insertlicence.GiveMeLicence(), skeyp, false)) { MessageBox.Show("No está autorizado!"); SameUser = true; return false; } return true; } } catch { return false; } return false; }