private void loadAccountsList() { mCurrentAccount = null; listAccounts.Items.Clear(); listAccounts.SelectedIndex = -1; allAccounts = MobileAuthenticatorFileHandler.GetAllAccounts(); if (allAccounts.Length > 0) { for (int i = 0; i < allAccounts.Length; i++) { SteamGuardAccount account = allAccounts[i]; listAccounts.Items.Add(account.AccountName); } listAccounts.SelectedIndex = 0; } btnDelete.Enabled = btnTradeConfirmations.Enabled = allAccounts.Length > 0; }
private void btnDelete_Click(object sender, EventArgs e) { if (mCurrentAccount == null) { return; } string confCode = mCurrentAccount.GenerateSteamGuardCode(); InputForm confirmationDialog = new InputForm("Removing the authenticator from " + mCurrentAccount.AccountName + ". Enter confirmation code " + confCode); confirmationDialog.ShowDialog(); if (confirmationDialog.Canceled) { return; } string enteredCode = confirmationDialog.txtBox.Text.ToUpper(); if (enteredCode != confCode) { MessageBox.Show("Confirmation codes do not match. Authenticator has not been unlinked."); return; } bool success = mCurrentAccount.DeactivateAuthenticator(); if (success) { MessageBox.Show("Authenticator unlinked. maFile will be deleted after hitting okay. If you need to make a backup, now's the time."); MobileAuthenticatorFileHandler.DeleteMaFile(mCurrentAccount); this.loadAccountsList(); } else { MessageBox.Show("Authenticator unable to be removed."); } }
private void btnSteamLogin_Click(object sender, EventArgs e) { string username = txtUsername.Text; string password = txtPassword.Text; mUserLogin = new UserLogin(username, password); LoginResult response = LoginResult.BadCredentials; while ((response = mUserLogin.DoLogin()) != LoginResult.LoginOkay) { switch (response) { case LoginResult.NeedEmail: InputForm emailForm = new InputForm("Enter the code sent to your email:"); emailForm.ShowDialog(); if (emailForm.Canceled) { this.Close(); return; } mUserLogin.EmailCode = emailForm.txtBox.Text; break; case LoginResult.NeedCaptcha: System.Diagnostics.Process.Start(String.Format("{0}/public/captcha.php?gid={1}", APIEndpoints.COMMUNITY_BASE, mUserLogin.CaptchaGID)); InputForm captchaForm = new InputForm("Enter the captcha that opened in your browser:"); captchaForm.ShowDialog(); if (captchaForm.Canceled) { this.Close(); return; } mUserLogin.CaptchaText = captchaForm.txtBox.Text; break; case LoginResult.Need2FA: MessageBox.Show("This account already has a mobile authenticator linked to it. Please remove that first."); this.Close(); return; break; } } //Login succeeded SessionData session = mUserLogin.Session; AuthenticatorLinker linker = new AuthenticatorLinker(session); AuthenticatorLinker.LinkResult linkResponse = AuthenticatorLinker.LinkResult.GeneralFailure; while ((linkResponse = linker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization) { switch (linkResponse) { case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber: string phoneNumber = ""; while (!PhoneNumberOkay(phoneNumber)) { InputForm phoneNumberForm = new InputForm("Enter your phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890"); phoneNumberForm.txtBox.Text = "+1 "; phoneNumberForm.ShowDialog(); if (phoneNumberForm.Canceled) { this.Close(); return; } phoneNumber = FilterPhoneNumber(phoneNumberForm.txtBox.Text); } linker.PhoneNumber = phoneNumber; break; case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber: linker.PhoneNumber = null; break; case AuthenticatorLinker.LinkResult.GeneralFailure: this.Close(); return; break; } } //Save the file immediately; losing this would be bad. if (!MobileAuthenticatorFileHandler.SaveMaFile(linker.LinkedAccount)) { MessageBox.Show("Unable to save mobile authenticator file. The mobile authenticator has not been linked."); this.Close(); return; } MessageBox.Show("The Mobile Authenticator has not yet been linked. Before finalizing the authenticator, please write down your revocation code: " + linker.LinkedAccount.RevocationCode); AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure; while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success) { InputForm smsCodeForm = new InputForm("Please input the SMS code sent to your phone."); smsCodeForm.ShowDialog(); if (smsCodeForm.Canceled) { MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount); this.Close(); return; } InputForm confirmRevocationCode = new InputForm("Please enter your revocation code to ensure you've saved it."); confirmRevocationCode.ShowDialog(); if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode) { MessageBox.Show("Revocation code incorrect; the authenticator has not been linked."); MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount); this.Close(); return; } string smsCode = smsCodeForm.txtBox.Text; finalizeResponse = linker.FinalizeAddAuthenticator(smsCode); switch (finalizeResponse) { case AuthenticatorLinker.FinalizeResult.BadSMSCode: continue; break; case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes: MessageBox.Show("Unable to generate the proper codes to finalize this authenticator. The authenticator should not have been linked. In the off-chance it was, please write down your revocation code, as this is the last chance to see it: " + linker.LinkedAccount.RevocationCode); MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount); this.Close(); return; break; case AuthenticatorLinker.FinalizeResult.GeneralFailure: MessageBox.Show("Unable to finalize this authenticator. The authenticator should not have been linked. In the off-chance it was, please write down your revocation code, as this is the last chance to see it: " + linker.LinkedAccount.RevocationCode); MobileAuthenticatorFileHandler.DeleteMaFile(linker.LinkedAccount); this.Close(); return; } } //Linked, finally. Re-save with FullyEnrolled property. MobileAuthenticatorFileHandler.SaveMaFile(linker.LinkedAccount); MessageBox.Show("Mobile authenticator successfully linked. Please write down your revocation code: " + linker.LinkedAccount.RevocationCode); this.Close(); }