コード例 #1
0
        private void LoginBtn_Click(object sender, RoutedEventArgs e)
        {
            UserName.IsTabStop = PassWord.IsTabStop = false;
            ErrorLabel.Visibility = LoginBtn.Visibility = Visibility.Collapsed;
            Progress.Visibility = Visibility.Visible;
            UserName.IsTabStop = PassWord.IsTabStop = true;

            if (login == null || login.Username != UserName.Text)
            {
                login = new UserLogin(UserName.Text, PassWord.Password);
            }

            login.TwoFactorCode = TwoFactorCode.Text.ToUpper();
            login.EmailCode = EmailCode.Text.ToUpper();
            login.CaptchaText = CaptchaText.Text;

            login.DoLogin(async response =>
            {
                await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    ProcessLoginResponse(response);
                });
            });
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: Nonickn/SteamAuth
        static void Main(string[] args)
        {
            //This basic loop will log into user accounts you specify, enable the mobile authenticator, and save a maFile (mobile authenticator file)
            while (true)
            {
                Console.WriteLine("Enter user/password: "******"Please enter your email code: ");
                            string code = Console.ReadLine();
                            login.EmailCode = code;
                            break;

                        case LoginResult.NeedCaptcha:
                            System.Diagnostics.Process.Start(APIEndpoints.COMMUNITY_BASE + "/public/captcha.php?gid=" + login.CaptchaGID); //Open a web browser to the captcha image
                            Console.WriteLine("Please enter captcha text: ");
                            string captchaText = Console.ReadLine();
                            login.CaptchaText = captchaText;
                            break;

                        case LoginResult.Need2FA:
                            Console.WriteLine("Please enter your mobile authenticator code: ");
                            code = Console.ReadLine();
                            login.TwoFactorCode = code;
                            break;
                    }
                }

                AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
                linker.PhoneNumber = null; //Set this to non-null to add a new phone number to the account.
                var result = linker.AddAuthenticator();

                if (result != AuthenticatorLinker.LinkResult.AwaitingFinalization)
                {
                    Console.WriteLine("Failed to add authenticator: " + result);
                    continue;
                }

                try
                {
                    string sgFile = JsonConvert.SerializeObject(linker.LinkedAccount, Formatting.Indented);
                    string fileName = linker.LinkedAccount.AccountName + ".maFile";
                    File.WriteAllText(fileName, sgFile);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Console.WriteLine("EXCEPTION saving maFile. For security, authenticator will not be finalized.");
                    continue;
                }

                Console.WriteLine("Please enter SMS code: ");
                string smsCode = Console.ReadLine();
                var linkResult = linker.FinalizeAddAuthenticator(smsCode);

                if (linkResult != AuthenticatorLinker.FinalizeResult.Success)
                {
                    Console.WriteLine("Unable to finalize authenticator: " + linkResult);
                }
            }
        }
コード例 #3
0
        private void btnSteamLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            if (LoginReason == LoginType.Android)
            {
                FinishExtract(username, password);
                return;
            }
            else if (LoginReason == LoginType.Refresh)
            {
                RefreshLogin(username, password);
                return;
            }

            var userLogin = new UserLogin(username, password);
            LoginResult response = LoginResult.BadCredentials;

            while ((response = userLogin.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;
                        }

                        userLogin.EmailCode = emailForm.txtBox.Text;
                        break;

                    case LoginResult.NeedCaptcha:
                        CaptchaForm captchaForm = new CaptchaForm(userLogin.CaptchaGID);
                        captchaForm.ShowDialog();
                        if (captchaForm.Canceled)
                        {
                            this.Close();
                            return;
                        }

                        userLogin.CaptchaText = captchaForm.CaptchaCode;
                        break;

                    case LoginResult.Need2FA:
                        MessageBox.Show("This account already has a mobile authenticator linked to it.\nRemove the old authenticator from your Steam account before adding a new one.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.BadRSA:
                        MessageBox.Show("Error logging in: Steam returned \"BadRSA\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.BadCredentials:
                        MessageBox.Show("Error logging in: Username or password was incorrect.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.TooManyFailedLogins:
                        MessageBox.Show("Error logging in: Too many failed logins, try again later.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.GeneralFailure:
                        MessageBox.Show("Error logging in: Steam returned \"GeneralFailure\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;
                }
            }

            //Login succeeded

            SessionData session = userLogin.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:
                        MessageBox.Show("Error adding your phone number. Steam returned \"GeneralFailure\".");
                        this.Close();
                        return;
                }
            }

            Manifest manifest = Manifest.GetManifest();
            string passKey = null;
            if (manifest.Entries.Count == 0)
            {
                passKey = manifest.PromptSetupPassKey("Please enter an encryption passkey. Leave blank or hit cancel to not encrypt (VERY INSECURE).");
            }
            else if (manifest.Entries.Count > 0 && manifest.Encrypted)
            {
                bool passKeyValid = false;
                while (!passKeyValid)
                {
                    InputForm passKeyForm = new InputForm("Please enter your current encryption passkey.");
                    passKeyForm.ShowDialog();
                    if (!passKeyForm.Canceled)
                    {
                        passKey = passKeyForm.txtBox.Text;
                        passKeyValid = manifest.VerifyPasskey(passKey);
                        if (!passKeyValid)
                        {
                            MessageBox.Show("That passkey is invalid. Please enter the same passkey you used for your other accounts.");
                        }
                    }
                    else
                    {
                        this.Close();
                        return;
                    }
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
            {
                manifest.RemoveAccount(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)
                {
                    manifest.RemoveAccount(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.");
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                string smsCode = smsCodeForm.txtBox.Text;
                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);

                switch (finalizeResponse)
                {
                    case AuthenticatorLinker.FinalizeResult.BadSMSCode:
                        continue;

                    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);
                        manifest.RemoveAccount(linker.LinkedAccount);
                        this.Close();
                        return;

                    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);
                        manifest.RemoveAccount(linker.LinkedAccount);
                        this.Close();
                        return;
                }
            }

            //Linked, finally. Re-save with FullyEnrolled property.
            manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            MessageBox.Show("Mobile authenticator successfully linked. Please write down your revocation code: " + linker.LinkedAccount.RevocationCode);
            this.Close();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        /// <summary>
        /// Handles logging in after data has been extracted from Android phone
        /// </summary>
        /// <param name="username">Steam username</param>
        /// <param name="password">Steam password</param>
        private async void FinishExtract(string username, string password)
        {
            long steamTime = await TimeAligner.GetSteamTimeAsync();
            Manifest man = Manifest.GetManifest();

            androidAccount.FullyEnrolled = true;

            UserLogin 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:
                        CaptchaForm captchaForm = new CaptchaForm(mUserLogin.CaptchaGID);
                        captchaForm.ShowDialog();
                        if (captchaForm.Canceled)
                        {
                            this.Close();
                            return;
                        }

                        mUserLogin.CaptchaText = captchaForm.CaptchaCode;
                        break;

                    case LoginResult.Need2FA:
                        mUserLogin.TwoFactorCode = androidAccount.GenerateSteamGuardCodeForTime(steamTime);
                        break;

                    case LoginResult.BadRSA:
                        MessageBox.Show("Error logging in: Steam returned \"BadRSA\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.BadCredentials:
                        MessageBox.Show("Error logging in: Username or password was incorrect.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.TooManyFailedLogins:
                        MessageBox.Show("Error logging in: Too many failed logins, try again later.", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;

                    case LoginResult.GeneralFailure:
                        MessageBox.Show("Error logging in: Steam returned \"GeneralFailure\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        this.Close();
                        return;
                }
            }

            androidAccount.Session = mUserLogin.Session;

            HandleManifest(man);
        }
コード例 #6
0
ファイル: Bot.cs プロジェクト: chrschmidt/ArchiSteamFarm
		private bool LinkMobileAuthenticator() {
			if (SteamGuardAccount != null) {
				return false;
			}

			Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName);
			UserLogin userLogin = new UserLogin(SteamLogin, SteamPassword);
			LoginResult loginResult;
			while ((loginResult = userLogin.DoLogin()) != LoginResult.LoginOkay) {
				switch (loginResult) {
					case LoginResult.NeedEmail:
						userLogin.EmailCode = Program.GetUserInput(BotName, Program.EUserInputType.SteamGuard);
						break;
					default:
						Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
						return false;
				}
			}

			AuthenticatorLinker authenticatorLinker = new AuthenticatorLinker(userLogin.Session);

			AuthenticatorLinker.LinkResult linkResult;
			while ((linkResult = authenticatorLinker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization) {
				switch (linkResult) {
					case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
						authenticatorLinker.PhoneNumber = Program.GetUserInput(BotName, Program.EUserInputType.PhoneNumber);
						break;
					default:
						Logging.LogGenericError("Unhandled situation: " + linkResult, BotName);
						return false;
				}
			}

			SteamGuardAccount = authenticatorLinker.LinkedAccount;

			try {
				File.WriteAllText(MobileAuthenticatorFile, JsonConvert.SerializeObject(SteamGuardAccount));
			} catch (Exception e) {
				Logging.LogGenericException(e, BotName);
				return false;
			}

			AuthenticatorLinker.FinalizeResult finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(Program.GetUserInput(BotName, Program.EUserInputType.SMS));
			if (finalizeResult != AuthenticatorLinker.FinalizeResult.Success) {
				Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName);
				DelinkMobileAuthenticator();
				return false;
			}

			Logging.LogGenericInfo("Successfully linked ASF as new mobile authenticator for this account!", BotName);
			Program.GetUserInput(BotName, Program.EUserInputType.RevocationCode, SteamGuardAccount.RevocationCode);
			return true;
		}
コード例 #7
0
        private static void SteamAuthLogin()
        {
            var authLogin = new UserLogin(_config.Username, _config.Password);
            LoginResult result;
            do
            {
                result = authLogin.DoLogin();
                switch (result)
                {
                    case LoginResult.NeedEmail:
                        Console.Write("An email was sent to this account's address, please enter the code here to continue: ");
                        authLogin.EmailCode = Console.ReadLine();
                        break;
                    case LoginResult.NeedCaptcha:
                        Process.Start("https://steamcommunity.com/public/captcha.php?gid=" + authLogin.CaptchaGID);
                        Console.Write("Please enter the captcha that just opened up on your default browser: ");
                        authLogin.CaptchaText = Console.ReadLine();
                        break;
                    case LoginResult.Need2FA:
                        Console.Write("Please enter in your authenticator code: ");
                        authLogin.TwoFactorCode = Console.ReadLine();
                        break;
                    default:
                        throw new Exception("Case was not accounted for. Case: " + result);
                }
            } while (result != LoginResult.LoginOkay);

            AuthenticatorLinker linker = new AuthenticatorLinker(authLogin.Session);
            Console.Write("Please enter the number you wish to associate this account in the format +1XXXXXXXXXX where +1 is your country code, leave blank if no new number is desired: ");

            string phoneNumber = Console.ReadLine();
            if (string.IsNullOrWhiteSpace(phoneNumber)) phoneNumber = null;
            linker.PhoneNumber = phoneNumber;

            AuthenticatorLinker.LinkResult linkResult = linker.AddAuthenticator();
            if (linkResult != AuthenticatorLinker.LinkResult.AwaitingFinalization)
            {
                Console.WriteLine("Could not add authenticator: " + linkResult);
                Console.WriteLine(
                    "If you attempted to link an already linked account, please tell FatherFoxxy to get off his ass and implement the new stuff.");
                return;
            }

            if (!SaveMobileAuth(linker))
            {
                Console.WriteLine("Issue saving auth file, link operation abandoned.");
                return;
            }

            Console.WriteLine(
                "You should have received an SMS code, please input it here. If the code does not arrive, please input a blank line to abandon the operation.");
            AuthenticatorLinker.FinalizeResult finalizeResult;
            do
            {
                Console.Write("SMS Code: ");
                string smsCode = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(smsCode)) return;
                finalizeResult = linker.FinalizeAddAuthenticator(smsCode);

            } while (finalizeResult != AuthenticatorLinker.FinalizeResult.BadSMSCode);
        }
コード例 #8
0
        /// <summary>
        /// Login button
        /// </summary>
        private void loginButton_Click(object sender, EventArgs e)
        {
            string susername = usernameText.Text;
            string spassword = passwordText.Text;

            if(susername.Length > 0 && spassword.Length > 0)
            {
                userLogin = new UserLogin(susername, spassword);
                LoginResult loginres = LoginResult.BadCredentials;

                while((loginres = userLogin.DoLogin()) != LoginResult.LoginOkay)
                {
                    /*We need to enter the email code to access the account*/
                    if(loginres == LoginResult.NeedEmail)
                    {
                        InputForm emailForm = new InputForm("Enter the code sent to the email account associated with the account.");
                        emailForm.ShowDialog();
                        if(emailForm.inputCancelled)
                        {
                            Close();
                            return;
                        }

                        userLogin.EmailCode = emailForm.inputText.Text;
                        continue;
                    }

                    /*We need the captcha ...*/
                    if(loginres == LoginResult.NeedCaptcha)
                    {
                        Process.Start(string.Format("{0}/public/captcha.php?gid={1}", APIEndpoints.COMMUNITY_BASE, userLogin.CaptchaGID));

                        InputForm captchaForm = new InputForm("Enter the captcha code that is showing in your browser.");
                        captchaForm.ShowDialog();
                        if(captchaForm.inputCancelled)
                        {
                            Close();
                            return;
                        }

                        userLogin.CaptchaText = captchaForm.inputText.Text;
                        continue;
                    }

                    /*We need mobile auth code ...*/
                    /*The user needs to remove existing authenticator before we can proceed, so we'll just bail out*/
                    if(loginres == LoginResult.Need2FA)
                    {
                        MessageBox.Show("Please remove the existing authenticator device you have attatched to your account to in order to proceed.");
                        Close();
                        return;
                    }

                    /*Incorrect password or similar*/
                    if(loginres == LoginResult.GeneralFailure)
                    {
                        MessageBox.Show("Trouble logging in.\nWrong password?");
                        Close();
                        return;
                    }
                }

                /*Login successful, proceed*/
                SessionData sessionData = userLogin.Session;
                AuthenticatorLinker authLinker = new AuthenticatorLinker((sessionData));
                AuthenticatorLinker.LinkResult authResult = AuthenticatorLinker.LinkResult.GeneralFailure;
                while ((authResult = authLinker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization)
                {
                    /*We need phone number to proceed*/
                    if(authResult == AuthenticatorLinker.LinkResult.MustProvidePhoneNumber)
                    {
                        string phoneNumber = string.Empty;
                        while(!ValidPhoneNumberInput(phoneNumber))
                        {
                            InputForm phoneNumberForm = new InputForm("Enter your phone number in the following format:\n+1 123-456-7890");
                            phoneNumberForm.inputText.Text = "+1 ";
                            phoneNumberForm.ShowDialog();
                            if(phoneNumberForm.inputCancelled)
                            {
                                Close();
                                return;
                            }

                            phoneNumber = FilterPhoneNumber(phoneNumberForm.inputText.Text);
                        }

                        authLinker.PhoneNumber = phoneNumber;
                        continue;
                    }

                    /*Remove previous number attatched to the account*/
                    if(authResult == AuthenticatorLinker.LinkResult.MustRemovePhoneNumber)
                    {
                        authLinker.PhoneNumber = string.Empty;
                        continue;
                    }

                    /*Oops*/
                    if(authResult == AuthenticatorLinker.LinkResult.GeneralFailure)
                    {
                        MessageBox.Show("Something bad happened...");
                        Close();
                        return;
                    }
                }

                /*Taking a pause to save the information that we've gathered thus far*/
                if(!FileHandler.SaveSGAFile(authLinker.LinkedAccount))
                {
                    MessageBox.Show("Unable to save the current data. The authenticator has not been linked.", "Error");
                    Close();
                    return;
                }

                /*Final checks*/
                AuthenticatorLinker.FinalizeResult finalRes = AuthenticatorLinker.FinalizeResult.GeneralFailure;
                while(finalRes != AuthenticatorLinker.FinalizeResult.Success)
                {
                    /*Get SMS code that was sent to users phone, providing the number was correct*/
                    InputForm smsForm = new InputForm("Enter the SMS code you received on your phone.");
                    smsForm.ShowDialog();
                    if(smsForm.inputCancelled)
                    {
                        /*Delete file here*/
                        FileHandler.DeleteSGAFile(authLinker.LinkedAccount);
                        Close();
                        return;
                    }

                    /*Finalize the process and check last things*/
                    finalRes = authLinker.FinalizeAddAuthenticator(smsForm.inputText.Text);

                    /*Check if the SMS code was bad*/
                    if(finalRes == AuthenticatorLinker.FinalizeResult.BadSMSCode)
                    {
                        MessageBox.Show("Incorrect SMS code. Try again.");
                        continue;
                    }

                    /*General failure number one*/
                    if(finalRes == AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes
                        || finalRes == AuthenticatorLinker.FinalizeResult.GeneralFailure)
                    {
                        MessageBox.Show(string.Format("Unable to generate correct codes.\nThe authenticator has not been linked.\n\n"
                            + "However, please write the revocation code down just incase:\n\n  {0}", authLinker.LinkedAccount.RevocationCode), "Error");

                        /*Delete file here*/
                        FileHandler.DeleteSGAFile(authLinker.LinkedAccount);
                        Close();
                        return;
                    }
                }

                /*Finally done - save everything*/
                if(!FileHandler.SaveSGAFile(authLinker.LinkedAccount))
                {
                    MessageBox.Show("Save failed.");
                    //Do something about it
                }

                MessageBox.Show("Mobile authenticator successfully linked.\nRevocation code: " + authLinker.LinkedAccount.RevocationCode, "Success!");
                Close();
            }
            else
            {
                MessageBox.Show("Missing login details.");
            }
        }
コード例 #9
0
ファイル: Bot.cs プロジェクト: Ryzhehvost/ArchiSteamFarm
		private void ImportAuthenticator(string maFilePath) {
			if (BotDatabase.SteamGuardAccount != null || !File.Exists(maFilePath)) {
				return;
			}

			Logging.LogGenericInfo("Converting SDA .maFile into ASF format...", BotName);
			try {
				BotDatabase.SteamGuardAccount = JsonConvert.DeserializeObject<SteamGuardAccount>(File.ReadAllText(maFilePath));
				File.Delete(maFilePath);
				Logging.LogGenericInfo("Success!", BotName);
			} catch (Exception e) {
				Logging.LogGenericException(e, BotName);
				return;
			}

			// If this is SDA file, then we should already have everything ready
			if (BotDatabase.SteamGuardAccount.Session != null) {
				Logging.LogGenericInfo("Successfully finished importing mobile authenticator!", BotName);
				return;
			}

			// But here we're dealing with WinAuth authenticator
			Logging.LogGenericInfo("ASF requires a few more steps to complete authenticator import...", BotName);

			if (!InitializeLoginAndPassword()) {
				return;
			}

			UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword);
			LoginResult loginResult;
			while ((loginResult = userLogin.DoLogin()) != LoginResult.LoginOkay) {
				switch (loginResult) {
					case LoginResult.Need2FA:
						userLogin.TwoFactorCode = Program.GetUserInput(Program.EUserInputType.TwoFactorAuthentication, BotName);
						if (string.IsNullOrEmpty(userLogin.TwoFactorCode)) {
							return;
						}
						break;
					default:
						Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
						return;
				}
			}

			if (userLogin.Session == null) {
				BotDatabase.SteamGuardAccount = null;
				Logging.LogGenericError("Session is invalid, linking can't be completed!", BotName);
				return;
			}

			BotDatabase.SteamGuardAccount.FullyEnrolled = true;
			BotDatabase.SteamGuardAccount.Session = userLogin.Session;

			if (string.IsNullOrEmpty(BotDatabase.SteamGuardAccount.DeviceID)) {
				BotDatabase.SteamGuardAccount.DeviceID = Program.GetUserInput(Program.EUserInputType.DeviceID, BotName);
			}

			BotDatabase.Save();
			Logging.LogGenericInfo("Successfully finished importing mobile authenticator!", BotName);
		}
コード例 #10
0
ファイル: Bot.cs プロジェクト: Ryzhehvost/ArchiSteamFarm
		private void LinkMobileAuthenticator() {
			if (BotDatabase.SteamGuardAccount != null) {
				return;
			}

			Logging.LogGenericInfo("Linking new ASF MobileAuthenticator...", BotName);

			if (!InitializeLoginAndPassword()) {
				return;
			}

			UserLogin userLogin = new UserLogin(BotConfig.SteamLogin, BotConfig.SteamPassword);
			LoginResult loginResult;
			while ((loginResult = userLogin.DoLogin()) != LoginResult.LoginOkay) {
				switch (loginResult) {
					case LoginResult.NeedEmail:
						userLogin.EmailCode = Program.GetUserInput(Program.EUserInputType.SteamGuard, BotName);
						if (string.IsNullOrEmpty(userLogin.EmailCode)) {
							return;
						}
						break;
					default:
						Logging.LogGenericError("Unhandled situation: " + loginResult, BotName);
						return;
				}
			}

			AuthenticatorLinker authenticatorLinker = new AuthenticatorLinker(userLogin.Session);

			AuthenticatorLinker.LinkResult linkResult;
			while ((linkResult = authenticatorLinker.AddAuthenticator()) != AuthenticatorLinker.LinkResult.AwaitingFinalization) {
				switch (linkResult) {
					case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
						authenticatorLinker.PhoneNumber = Program.GetUserInput(Program.EUserInputType.PhoneNumber, BotName);
						if (string.IsNullOrEmpty(authenticatorLinker.PhoneNumber)) {
							return;
						}
						break;
					default:
						Logging.LogGenericError("Unhandled situation: " + linkResult, BotName);
						return;
				}
			}

			BotDatabase.SteamGuardAccount = authenticatorLinker.LinkedAccount;

			string sms = Program.GetUserInput(Program.EUserInputType.SMS, BotName);
			if (string.IsNullOrEmpty(sms)) {
				Logging.LogGenericWarning("Aborted!", BotName);
				DelinkMobileAuthenticator();
				return;
			}

			AuthenticatorLinker.FinalizeResult finalizeResult;
			while ((finalizeResult = authenticatorLinker.FinalizeAddAuthenticator(sms)) != AuthenticatorLinker.FinalizeResult.Success) {
				switch (finalizeResult) {
					case AuthenticatorLinker.FinalizeResult.BadSMSCode:
						sms = Program.GetUserInput(Program.EUserInputType.SMS, BotName);
						if (string.IsNullOrEmpty(sms)) {
							Logging.LogGenericWarning("Aborted!", BotName);
							DelinkMobileAuthenticator();
							return;
						}
						break;
					default:
						Logging.LogGenericError("Unhandled situation: " + finalizeResult, BotName);
						DelinkMobileAuthenticator();
						return;
				}
			}

			// Ensure that we also save changes made by finalization step (if any)
			BotDatabase.Save();

			Logging.LogGenericInfo("Successfully linked ASF as new mobile authenticator for this account!", BotName);
			Program.GetUserInput(Program.EUserInputType.RevocationCode, BotName, BotDatabase.SteamGuardAccount.RevocationCode);
		}