private void tbLicenseKey_TextChanged(object sender, EventArgs e) { if (tbLicenseKey.Text == string.Empty) { labelValidity.Text = ""; button4.Enabled = false; return; } //AptimaLicenseInfo li = AptimaLicenseVerifier.VerifyLicenseKey(tbLicenseKey.Text); AptimaLicenseInfo li = AptimaLicenseVerifier.VerifyLicenseKey(_licenseKey.ToActualString()); if (li.IsValid) { labelValidity.Text = "It's Valid!"; button4.Enabled = true; } }
private void button2_Click(object sender, EventArgs e) { bool toReturn = false; if (tbRandomNumber.Text == string.Empty) { toReturn = true; } if (tbNumOfUsers.Text == string.Empty) { toReturn = true; } if (tbMinorVersion.Text == string.Empty) { toReturn = true; } if (tbMajorVersion.Text == string.Empty) { toReturn = true; } if (toReturn) { MessageBox.Show("Missing required field."); return; } if (Convert.ToInt32(tbNumOfUsers.Text) > 255) { MessageBox.Show("Too many bits (255 Max)"); return; } StringBuilder inputString = new StringBuilder(); //[_DDD][04][01][2007][10][10][2][A8][RAND] try { inputString.Append(productKeyMapping[Convert.ToString(cbProductName.SelectedItem)]); } catch { MessageBox.Show("Error trying to handle product code."); return; } try { if (tbMajorVersion.Text.Length == 1) { inputString.Append("0"); } inputString.Append(tbMajorVersion.Text); if (tbMinorVersion.Text.Length == 1) { inputString.Append("0"); } inputString.Append(tbMinorVersion.Text); inputString.AppendFormat("{0:yyyyMMdd}", dtExpirationDate.Value); inputString.Append(cbLicenseType.SelectedIndex); inputString.Append(AptimaLicenseVerifier.ConvertNumberStringToHex(tbNumOfUsers.Text)); inputString.Append(tbRandomNumber.Text); } catch { throw new Exception("Error trying to create input string"); } labelInputString.Text = inputString.ToString(); labelLength2.Text = String.Format("Length: {0}", labelInputString.Text.Length); //tbLicenseKey.Text = AptimaLicenseVerifier.GenerateLicenseKey(labelInputString.Text); _licenseKey = new Key(AptimaLicenseVerifier.GenerateLicenseKey(labelInputString.Text)); tbLicenseKey.Text = _licenseKey.ToString(); labelLength.Text = String.Format("Length: {0}", _licenseKey.ToActualString().Length); }