/// <summary> /// Perform a verification of the restore code in the background by checking it with the servers /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void VerifyRestoreCode(object sender, DoWorkEventArgs e) { Authenticator auth = e.Argument as Authenticator; // check if this authenticator is too old to be restored try { Authenticator testrestore = new Authenticator(); testrestore.Restore(auth.Serial, auth.RestoreCode); auth.RestoreCodeVerified = true; e.Result = null; } catch (InvalidRestoreCodeException) { e.Result = "This authenticator was created before the restore capability existed and so the restore code will not work.\n\n" + "You will need to remove this authenticator from your Battle.net account and create a new one."; } catch (InvalidRestoreResponseException) { // ignore the validation if servers are down } catch (Exception ex2) { e.Result = "Oops. An error (" + ex2.Message + ") occured whilst validating your restore code." + "Please log a ticket at http://code.google.com/p/winauth so we can fix this."; } }
/// <summary> /// Click the OK button to restore the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click_1(object sender, EventArgs e) { string serial = (serial1Field.Text + serial2Field.Text + serial3Field.Text + serial4Field.Text).Trim().ToUpper(); if (serial.Length != 14) { MessageBox.Show(this, "Invalid serial number.\n\n - must be something like US-1234-1234-1234.", WinAuth.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } string restorecode = restoreCodeField.Text.Trim().ToUpper(); if (restorecode.Length != 10) { MessageBox.Show(this, "Invalid restore code.\n\n - must contain 10 letters and numbers.", WinAuth.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // restore the authenticator try { Authenticator auth = new Authenticator(); auth.Restore(serial, restorecode); this.Authenticator = auth; MessageBox.Show(this, "Your authenticator has been restored.\n\nYou will now be prompted where to save your new authenticator and choose your encryption level.", WinAuth.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Information); // ok to continue DialogResult = System.Windows.Forms.DialogResult.OK; } catch (InvalidRestoreResponseException re) { MessageBox.Show(this, re.Message, WinAuth.APPLICATION_NAME, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }