public bool CheckNewLicense(string inLicCode, int inProduct) { bool ok = true; License thenewlicense = new License(); //uint theCRC = 0; if (inLicCode.Length == 24) { try { thenewlicense.mClient = Convert.ToUInt16((inLicCode[2] - 65) * 26 * 26 + (inLicCode[3] - 65) * 26 + (inLicCode[5] - 65)); thenewlicense.mProduct = Convert.ToUInt16((inLicCode[6] - 65) * 26 * 26 + (inLicCode[7] - 65) * 26 + (inLicCode[8] - 65)); uint temp = Convert.ToUInt16((inLicCode[13] - 65) * 26 * 26 + (inLicCode[15] - 65) * 26 + (inLicCode[16] - 65)); thenewlicense.mCRC = Convert.ToUInt32((((inLicCode[10] - 65) * 26 * 26 + (inLicCode[11] - 65) * 26 + (inLicCode[12] - 65)) << 10) + (temp >> 4)); thenewlicense.mKey = temp & 15; thenewlicense.mStart = Convert.ToUInt32((inLicCode[17] - 65) * 26 * 26 + (inLicCode[18] - 65) * 26 + (inLicCode[20] - 65)); thenewlicense.mEnd = Convert.ToUInt32((inLicCode[21] - 65) * 26 * 26 + (inLicCode[22] - 65) * 26 + (inLicCode[23] - 65)); string totalstring = thenewlicense.mClient.ToString() + thenewlicense.mProduct.ToString() + thenewlicense.mKey.ToString() + thenewlicense.mStart.ToString() + thenewlicense.mEnd.ToString(); Crc32 newCrc = new Crc32(); uint newcrc = newCrc.ComputeChecksum(StrToByteArray(totalstring)); newcrc = newcrc & 0x00ffffff; thenewlicense.mValid = newcrc == thenewlicense.mCRC; //if (thenewlicense.mValid && inProduct == thenewlicense.mProduct) if (AddLicense(thenewlicense)) { ok = true; } else { ok = false; } } catch (Exception) { MessageBox.Show("This license is not valid.", "Problem", MessageBoxButtons.OK); ok = false; } //else // ok = false; /* * mStart = (inLicCode[17]-'A')*26*26 + (inLicCode[18]-'A')*26 + (inLicCode[20]-'A'); * mEnd = (inLicCode[21]-'A')*26*26 + (inLicCode[22]-'A')*26 + (inLicCode[23]-'A'); */ //SetCRC (); //mValid = (theCRC == mCRC); } else { MessageBox.Show("This license is not valid.", "Problem", MessageBoxButtons.OK); ok = false; } //newCrc.ComputeChecksum( return(ok); }
internal bool CheckNewLicense(string inLicCode) { bool ok = true; int test; License thenewlicense = new License(); uint theCRC = 0; if (inLicCode.Length == 24) { try { thenewlicense.mClient = Convert.ToUInt16((inLicCode[2] - 65) * 26 * 26 + (inLicCode[3] - 65) * 26 + (inLicCode[5] - 65)); thenewlicense.mProduct = Convert.ToUInt16((inLicCode[6] - 65) * 26 * 26 + (inLicCode[7] - 65) * 26 + (inLicCode[8] - 65)); uint temp = Convert.ToUInt16((inLicCode[13] - 65) * 26 * 26 + (inLicCode[15] - 65) * 26 + (inLicCode[16] - 65)); thenewlicense.mCRC = Convert.ToUInt32((((inLicCode[10] - 65) * 26 * 26 + (inLicCode[11] - 65) * 26 + (inLicCode[12] - 65)) << 10) + (temp >> 4)); thenewlicense.mKey = temp & 15; thenewlicense.mStart = Convert.ToUInt32((inLicCode[17] - 65) * 26 * 26 + (inLicCode[18] - 65) * 26 + (inLicCode[20] - 65)); thenewlicense.mEnd = Convert.ToUInt32((inLicCode[21] - 65) * 26 * 26 + (inLicCode[22] - 65) * 26 + (inLicCode[23] - 65)); string totalstring = thenewlicense.mClient.ToString() + thenewlicense.mProduct.ToString() + thenewlicense.mKey.ToString() + thenewlicense.mStart.ToString() + thenewlicense.mEnd.ToString(); Crc32 newCrc = new Crc32(); uint newcrc = newCrc.ComputeChecksum(StrToByteArray(totalstring)); newcrc = newcrc & 0x00ffffff; thenewlicense.mValid = newcrc == thenewlicense.mCRC; if (!thenewlicense.mValid) { MessageBox.Show("This License is not valid!"); return(false); } int returnint = AddLicense(thenewlicense); if (returnint == 0) { ok = true; } else { string messageboxstring = ""; switch (returnint) { case 1: messageboxstring = "This license is not for this client!"; break; case 2: messageboxstring = "This license is not for this product!"; break; // JPB This is a test change, removing redundant code... //case 3: // messageboxstring = "This license end date is shorter then the current end date!"; // break; case 4: messageboxstring = "This license end date is already expired!"; break; case 5: messageboxstring = "Unable to save new license!"; break; } MessageBox.Show(messageboxstring); ok = false; } } catch (Exception) { MessageBox.Show("This license is not valid.", "Problem", MessageBoxButtons.OK); ok = false; } //else // ok = false; /* * mStart = (inLicCode[17]-'A')*26*26 + (inLicCode[18]-'A')*26 + (inLicCode[20]-'A'); * mEnd = (inLicCode[21]-'A')*26*26 + (inLicCode[22]-'A')*26 + (inLicCode[23]-'A'); */ //SetCRC (); //mValid = (theCRC == mCRC); } else { MessageBox.Show("This license is not valid.", "Problem", MessageBoxButtons.OK); ok = false; } //newCrc.ComputeChecksum( return(ok); }