using framework_library; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace framework_business { public class licenceHandler { /// /// Procedure to validate a licence /// /// /// /// /// /// oLicenceResult public static oLicenceResult ValidateLicence(string customerName, string licenceKey, DateTime licenceDate, string customerCode) { oLicenceResult result = new oLicenceResult(); bool failed = false; encryption encrypt = new encryption("3v0l#t!0ns0ftw@r3"); oLicence licValidate = GetLicence(licenceKey); //validate licence if (licValidate.licenceKey == licenceKey) { if (licValidate.customerName.Trim() != customerName.Trim()) { failed = true; result.failedReasons.Add("Customer Name does not match."); } if (licValidate.licenceDate.ToString("yyyy-MM-dd") != licenceDate.ToString("yyyy-MM-dd")) { failed = true; result.failedReasons.Add("License Date does not match."); } if (licValidate.customerCode != customerCode) { failed = true; result.failedReasons.Add("Customer Code dont match."); } } else { failed = true; result.failedReasons.Add("Invalid Licence."); } if (failed)//failed result.successful = false; else result.successful = true; return result; } /// /// Create a License /// /// /// public static oLicence CreateLicence(oLicence Licence) { oLicence result = new oLicence(); encryption encrypt = new encryption("3v0l#t!0ns0ftw@r3"); StringBuilder data = new StringBuilder(); //build up pipe delimited data to be encrypted and hashed //customer name data.Append(Licence.customerName + "|"); //licence date data.Append(Licence.licenceDate.ToString("yyyy-MM-dd") + "|"); //customer code data.Append(Licence.customerCode); //encrypt data string key = encrypt.encryptValue(data.ToString()); if (key != String.Empty) { Licence.licenceKey = key; } result = Licence; return result; } /// /// Get License /// /// /// public static oLicence GetLicence(string licenceKey) { oLicence result = new oLicence(); encryption encrypt = new encryption("3v0l#t!0ns0ftw@r3"); string data = encrypt.decryptData(licenceKey); string[] dataArr = data.Split(char.Parse("|")); if (dataArr.Length == 3) { result.customerName = dataArr[0]; result.licenceDate = DateTime.Parse(dataArr[1]); result.customerCode = dataArr[2]; result.licenceKey = licenceKey; } return result; } } }