private void button_generate_Click(object sender, EventArgs e)
        {
            var username       = textBox_account_name.Text.Trim();
            var password       = textBox_password.Text.Trim();
            var sharedSecret   = textBox_shared_secret.Text.Trim();
            var identitySecret = textBox_identity_secret.Text.Trim();

            button_generate.Enabled = false;
            button_generate.Text    = Resources.Form1_button_generate_Click_Generating___;

            new Thread(() =>
            {
                var authFile = Path.Combine("authfiles", string.Format("{0}.auth", username));
                Directory.CreateDirectory(Path.Combine(Application.StartupPath, "authfiles"));
                var steamGuardAccount = new SteamGuardAccount
                {
                    SharedSecret   = sharedSecret,
                    IdentitySecret = identitySecret
                };
                var login       = new UserLogin(username, password);
                var loginResult = login.DoLogin();
                if (loginResult == LoginResult.Need2FA)
                {
                    for (var i = 0; i < 3; i++)
                    {
                        TimeAligner.AlignTime();
                        login.TwoFactorCode = steamGuardAccount.GenerateSteamGuardCode();
                        loginResult         = login.DoLogin();
                        if (loginResult == LoginResult.LoginOkay)
                        {
                            break;
                        }
                    }
                    if (loginResult == LoginResult.LoginOkay)
                    {
                        steamGuardAccount.DeviceID = AuthenticatorLinker.GenerateDeviceID();
                        steamGuardAccount.Session  = login.Session;
                        File.WriteAllText(authFile, Newtonsoft.Json.JsonConvert.SerializeObject(steamGuardAccount));
                        MessageBox.Show(Resources.Form1_button_generate_Click_Successfully_generated_your_auth_file_, Resources.Form1_button_generate_Click_Success);
                        ResetGenerateButton();
                    }
                    else
                    {
                        MessageBox.Show(Resources.Form1_button_generate_Click_Error_logging_in__ + loginResult, Resources.Form1_button_generate_Click_Error);
                        ResetGenerateButton();
                    }
                }
                else
                {
                    MessageBox.Show(Resources.Form1_button_generate_Click_This_account_does_not_appear_to_have_2FA_enabled__Login_result__ + loginResult, Resources.Form1_button_generate_Click_Error);
                    ResetGenerateButton();
                }
            }).Start();
        }
Example #2
0
        /// <summary>
        /// Handles logging in to refresh session data. i.e. changing steam password.
        /// </summary>
        /// <param name="username">Steam username</param>
        /// <param name="password">Steam password</param>
        private async void RefreshLogin(string username, string password)
        {
            long steamTime = await TimeAligner.GetSteamTimeAsync();

            Manifest man = Manifest.GetManifest();

            account.FullyEnrolled = true;

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

            while ((response = mUserLogin.DoLogin()) != LoginResult.LoginOkay)
            {
                switch (response)
                {
                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 = account.GenerateSteamGuardCodeForTime(steamTime);
                    break;

                case LoginResult.BadRSA:
                    MessageBox.Show("错误记录:Steam返回“BadRSA”。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show("错误记录:用户名或密码不正确。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show("错误记录:太多次失败的登录,稍后再试。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show("错误记录:Steam返回\"GeneralFailure\".", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;
                }
            }

            account.Session = mUserLogin.Session;

            HandleManifest(man, true);
        }
Example #3
0
        static bool promptRefreshSession(SteamGuardAccount account)
        {
            Console.WriteLine("Your Steam credentials have expired. For trade and market confirmations to work properly, please login again.");
            string username = account.AccountName;

            Console.WriteLine($"Username: {username}");
            Console.Write("Password: "******"Logging in {username}... ");
            LoginResult loginResult = login.DoLogin();

            if (loginResult == LoginResult.Need2FA && !string.IsNullOrEmpty(account.SharedSecret))
            {
                // if we need a 2fa code, and we can generate it, generate a 2fa code and log in.
                Utils.Verbose(loginResult);
                TimeAligner.AlignTime();
                login.TwoFactorCode = account.GenerateSteamGuardCode();
                if (Verbose)
                {
                    Console.Write($"Logging in {username}... ");
                }
                loginResult = login.DoLogin();
            }
            Console.WriteLine(loginResult);
            if (loginResult == LoginResult.LoginOkay)
            {
                account.Session = login.Session;
            }

            if (account.RefreshSession())
            {
                Utils.Verbose("Session refreshed");
                Manifest.SaveAccount(account, Manifest.Encrypted);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void Login()
        {
            App.Logger.Info($"AuthWrapper.Login...");
            if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
            {
                throw new Exception($"{nameof(Username)} or {nameof(Password)} is empty");
            }
            LoginResult response = UserLogin.DoLogin();

            AuthLoginEvent?.Invoke(this, new AuthLoginEventArgs(response));
        }
Example #5
0
        public static UserLogin Login(string username, string password)
        {
            Console.WriteLine("Logging in with user \"{0}\".", username);
            var user        = new UserLogin(username, password);
            var loginResult = user.DoLogin();

            if (loginResult == LoginResult.NeedEmail)
            {
                Console.WriteLine("Email verification required. Waiting for code...");
                user.EmailCode = Console.ReadLine();
                loginResult    = user.DoLogin();
            }

            if (loginResult != LoginResult.LoginOkay)
            {
                Console.WriteLine("Login failed with result \"{0}\".", loginResult);
                return(null);
            }

            Console.WriteLine("Login successful.");
            return(user);
        }
Example #6
0
        public static void Login_An_Customize(string path_to_save, string username, string pass)
        {
            try
            {
                UserLogin login = new UserLogin(username, pass);

                LoginResult response = LoginResult.BadCredentials;
                while ((response = login.DoLogin()) != LoginResult.LoginOkay)
                {
                    Log.info($"Login Response: {response} on Account: {username}");
                    switch (response)
                    {
                    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;

                    default:
                        break;
                    }
                }

                string Region = GetAccountRegion(login.Session);

                File.AppendAllText(path_to_save, $"\nSteamID: {login.Session.SteamID}\nProfileLink: https://steamcommunity.com/profiles/{login.Session.SteamID}\nCreation Date:{DateTime.Now.ToShortDateString()}\nRegion:{Region}");
                Log.info($"Save SteamID64: {login.Session.SteamID} on Account: {username}");


                if (Main._Form1.ck_Set_NickNameRandom.Checked == true)
                {
                    Enable_Profile_Default(login.Session, username);
                }

                if (Main._Form1.ck_use_custom_avatar.Checked == true)
                {
                    Set_Custom_Avatar(login.Session);
                }

                if (Main._Form1.ck_GameAndInventory_Public.Checked == true)
                {
                    Set_GameAndInventory_Public(login.Session);
                }
            }
            catch (Exception ex)
            {
                Log.error("Erro To Customize Account " + username);
                Log.error(ex.Message);
            }
        }
Example #7
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);
                });
            });
        }
        private InternalUserLogin DoLogin()
        {
            var result = _userLogin.DoLogin();

            switch (result)
            {
            case LoginResult.NeedEmail:
            {
                var message = "Need to confirm email code in telegram";
                _logger.LogWarning(message);
                return(new InternalUserLogin(result, message));
            }

            case LoginResult.NeedCaptcha:
            {
                // need to open link and get text from captcha
                var captchaUrl = APIEndpoints.COMMUNITY_BASE + "/public/captcha.php?gid=" +
                                 _userLogin.CaptchaGID;
                var message = $"Need to confirm captcha text in telegram : {captchaUrl}";
                _logger.LogWarning(message);
                return(new InternalUserLogin(result, message));
            }

            case LoginResult.Need2FA:
            {
                var message = "Need to confirm mobile authenticator code text in telegram";
                _logger.LogWarning(message);
                return(new InternalUserLogin(result, message));
            }

            case LoginResult.BadCredentials:
                return(new InternalUserLogin(result, "Bad credentials"));

            case LoginResult.TooManyFailedLogins:
                return(new InternalUserLogin(result, "Too many failed logins"));

            case LoginResult.LoginOkay:
            {
                _profileSettings.SetUserLogin(_userLogin);
                return(new InternalUserLogin(LoginResult.LoginOkay));
            }

            default:
                return(new InternalUserLogin(result, "Unexpected login failure"));
            }
        }
        public Task <bool> ReloginAsync(SteamGuardAccount account, string password)
        {
            App.Logger.Trace($"AuthWrapper.ReloginAsync");
            return(Task.Run(async() => {
                bool result = false;
                try
                {
                    int counter = 0;
                    App.Logger.Trace($"AuthWrapper.ReloginAsync Try Relogin");
                    UserLogin userLogin = new UserLogin(account.AccountName, password);
                    LoginResult response = LoginResult.BadCredentials;
                    while (true)
                    {
                        counter++;
                        response = userLogin.DoLogin();
                        App.Logger.Trace($"AuthWrapper.ReloginAsync Response: {response}");
                        if (response == LoginResult.LoginOkay)
                        {
                            account.Session = userLogin.Session;
                            result = true;
                            break;
                        }
                        else if (response == LoginResult.Need2FA)
                        {
                            userLogin.TwoFactorCode = account.GenerateSteamGuardCode();
                        }
                        else if (counter >= MaxAttemps)
                        {
                            App.Logger.Warn($"AuthWrapper.ReloginAsync Max Attemps: {counter}");
                            break;
                        }
                        await Task.Delay(1000);
                    }
                    return result;
                }
                catch (Exception ex)
                {
                    App.Logger.Error($"AuthWrapper.ReloginAsync Error: {ex.Message}");
                    result = false;
                }
                App.Logger.Info($"AuthWrapper.ReloginAsync Result: {result}");

                return result;
            }));
        }
        public bool ReLogin(SteamGuardAccount account, string password)
        {
            App.Logger.Info($"AuthWrapper.Relogin...");
            bool result = false;

            try
            {
                int         counter   = 0;
                UserLogin   userLogin = new UserLogin(account.AccountName, password);
                LoginResult response  = LoginResult.BadCredentials;
                while (true)
                {
                    counter++;
                    response = userLogin.DoLogin();
                    App.Logger.Info($"AuthWrapper.Relogin Response: {response}");
                    if (response == LoginResult.LoginOkay)
                    {
                        account.Session = userLogin.Session;
                        result          = true;
                        break;
                    }
                    else if (response == LoginResult.Need2FA)
                    {
                        userLogin.TwoFactorCode = account.GenerateSteamGuardCode();
                    }
                    else if (counter >= MaxAttemps)
                    {
                        App.Logger.Warn($"AuthWrapper.Relogin Attemps: {counter}");
                        break;
                    }
                }
                return(result);
            }
            catch (Exception ex)
            {
                App.Logger.Error($"AuthWrapper.Relogin Error: {ex.Message}");
                result = false;
            }
            App.Logger.Info($"AuthWrapper.Relogin Result: {result}");

            return(result);
        }
Example #11
0
        static void processConfirmations(SteamGuardAccount account)
        {
            if (Verbose)
            {
                Console.WriteLine("Refeshing Session...");
            }
            if (account.RefreshSession())
            {
                if (Verbose)
                {
                    Console.WriteLine("Session refreshed");
                }
                Manifest.SaveAccount(account, Manifest.Encrypted);
            }
            else
            {
                if (Verbose)
                {
                    Console.WriteLine("Failed to refresh session");
                }
                Console.WriteLine("Your Steam credentials have expired. For trade and market confirmations to work properly, please login again.");
                string username = account.AccountName;
                Console.WriteLine($"Username: {username}");
                Console.Write("Password: "******"Logging in {username}... ");
                LoginResult loginResult = login.DoLogin();
                if (loginResult == LoginResult.Need2FA && !string.IsNullOrEmpty(account.SharedSecret))
                {
                    // if we need a 2fa code, and we can generate it, generate a 2fa code and log in.
                    if (Verbose)
                    {
                        Console.WriteLine(loginResult);
                    }
                    TimeAligner.AlignTime();
                    login.TwoFactorCode = account.GenerateSteamGuardCode();
                    if (Verbose)
                    {
                        Console.Write($"Logging in {username}... ");
                    }
                    loginResult = login.DoLogin();
                }
                Console.WriteLine(loginResult);
                if (loginResult == LoginResult.LoginOkay)
                {
                    account.Session = login.Session;
                }

                if (account.RefreshSession())
                {
                    if (Verbose)
                    {
                        Console.WriteLine("Session refreshed");
                    }
                    Manifest.SaveAccount(account, Manifest.Encrypted);
                }
                else
                {
                    Console.WriteLine("Failed to refresh session, aborting...");
                    return;
                }
            }
            Console.WriteLine("Retrieving trade confirmations...");
            var tradesTask = account.FetchConfirmationsAsync();

            tradesTask.Wait();
            var trades       = tradesTask.Result;
            var tradeActions = new TradeAction[trades.Length];

            for (var i = 0; i < tradeActions.Length; i++)
            {
                tradeActions[i] = TradeAction.Ignore;
            }
            if (trades.Length == 0)
            {
                Console.WriteLine($"No trade confirmations for {account.AccountName}.");
                return;
            }
            var selected      = 0;
            var colorAccept   = ConsoleColor.Green;
            var colorDeny     = ConsoleColor.Red;
            var colorIgnore   = ConsoleColor.Gray;
            var colorSelected = ConsoleColor.Yellow;
            var confirm       = false;

            do
            {
                Console.Clear();
                if (selected >= trades.Length)
                {
                    selected = trades.Length - 1;
                }
                else if (selected < 0)
                {
                    selected = 0;
                }
                Console.ResetColor();
                Console.WriteLine($"Trade confirmations for {account.AccountName}...");
                Console.WriteLine("No action will be made without your confirmation.");
                Console.WriteLine("[a]ccept   [d]eny   [i]gnore  [enter] Confirm  [q]uit");                 // accept = 1, deny = 0, ignore = -1
                Console.WriteLine();

                for (var t = 0; t < trades.Length; t++)
                {
                    ConsoleColor itemColor;
                    switch (tradeActions[t])
                    {
                    case TradeAction.Accept:
                        itemColor = colorAccept;
                        break;

                    case TradeAction.Deny:
                        itemColor = colorDeny;
                        break;

                    case TradeAction.Ignore:
                        itemColor = colorIgnore;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    Console.ForegroundColor = t == selected ? colorSelected : itemColor;

                    Console.WriteLine($"  [{t}] [{tradeActions[t]}] {trades[t].Description}");
                }
                var key = Console.ReadKey();
                switch (key.Key)
                {
                case ConsoleKey.UpArrow:
                case ConsoleKey.W:
                    selected--;
                    break;

                case ConsoleKey.DownArrow:
                case ConsoleKey.S:
                    selected++;
                    break;

                case ConsoleKey.A:
                    tradeActions[selected] = TradeAction.Accept;
                    break;

                case ConsoleKey.D:
                    tradeActions[selected] = TradeAction.Deny;
                    break;

                case ConsoleKey.I:
                    tradeActions[selected] = TradeAction.Ignore;
                    break;

                case ConsoleKey.Enter:
                    confirm = true;
                    break;

                case ConsoleKey.Escape:
                case ConsoleKey.Q:
                    Console.ResetColor();
                    Console.WriteLine("Quitting...");
                    return;

                default:
                    break;
                }
            } while (!confirm);
            Console.ResetColor();
            Console.WriteLine();
            Console.WriteLine("Processing...");
            for (var t = 0; t < trades.Length; t++)
            {
                bool success = false;
                switch (tradeActions[t])
                {
                case TradeAction.Accept:
                    if (Verbose)
                    {
                        Console.Write($"Accepting {trades[t].Description}...");
                    }
                    success = account.AcceptConfirmation(trades[t]);
                    break;

                case TradeAction.Deny:
                    if (Verbose)
                    {
                        Console.Write($"Denying {trades[t].Description}...");
                    }
                    success = account.AcceptConfirmation(trades[t]);
                    break;

                case TradeAction.Ignore:
                    if (Verbose)
                    {
                        Console.Write($"Ignoring {trades[t].Description}...");
                    }
                    success = true;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                if (Verbose)
                {
                    Console.WriteLine(success);
                }
            }
            Console.WriteLine("Done.");
        }
Example #12
0
        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);
                }
            }
        }
Example #13
0
        static void Setup(string username = "", string passkey = "")
        {
            if (Verbose)
            {
                Console.WriteLine("Opening manifest...");
            }
            Manifest = Manifest.GetManifest(true);

            if (string.IsNullOrWhiteSpace(username))
            {
                Console.Write("Username: "******"Password: "******"Logging in {username}... ");
                LoginResult loginResult = login.DoLogin();
                Console.WriteLine(loginResult);
                if (loginResult == LoginResult.NeedEmail)
                {
                    Console.Write("Email code: ");
                    emailCode = Console.ReadLine();
                    continue;
                }
                else if (loginResult == LoginResult.Need2FA)
                {
                    Console.Write("2FA code: ");
                    twoFactorCode = Console.ReadLine();
                    continue;
                }
                if (!login.LoggedIn)
                {
                    return;
                }
                break;
            }

            AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);

            AuthenticatorLinker.LinkResult linkResult = AuthenticatorLinker.LinkResult.GeneralFailure;

            do
            {
                linkResult = linker.AddAuthenticator();
                Console.WriteLine($"Link result: {linkResult}");
                switch (linkResult)
                {
                case AuthenticatorLinker.LinkResult.MustProvidePhoneNumber:
                    var phonenumber = "";
                    do
                    {
                        Console.WriteLine("Enter your mobile phone number in the following format: +{cC} phoneNumber. EG, +1 123-456-7890");
                        phonenumber        = Console.ReadLine();
                        phonenumber        = FilterPhoneNumber(phonenumber);
                        linker.PhoneNumber = phonenumber;
                    } while (!PhoneNumberOkay(phonenumber));
                    break;

                case AuthenticatorLinker.LinkResult.MustRemovePhoneNumber:
                    linker.PhoneNumber = null;
                    break;

                case AuthenticatorLinker.LinkResult.AwaitingFinalization:
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    Console.WriteLine("error: Unable to add your phone number. Steam returned GeneralFailure");
                    return;

                case AuthenticatorLinker.LinkResult.AuthenticatorPresent:
                    Console.WriteLine("An authenticator is already present.");
                    Console.WriteLine("If you have the revocation code (Rxxxxx), this program can remove it for you.");
                    Console.Write("Would you like to remove the current authenticator using your revocation code? (y/n) ");
                    var answer = Console.ReadLine();
                    if (answer != "y")
                    {
                        continue;
                    }
                    Console.Write("Revocation code (Rxxxxx): ");
                    var revocationCode = Console.ReadLine();
                    var account        = new SteamGuardAccount();
                    account.Session        = login.Session;
                    account.RevocationCode = revocationCode;
                    if (account.DeactivateAuthenticator())
                    {
                        Console.WriteLine("Successfully deactivated the current authenticator.");
                    }
                    else
                    {
                        Console.WriteLine("Deactivating the current authenticator was unsuccessful.");
                    }
                    continue;

                default:
                    Console.WriteLine($"error: Unexpected linker result: {linkResult}");
                    return;
                }
            } while (linkResult != AuthenticatorLinker.LinkResult.AwaitingFinalization);

            string passKey = null;

            if (Manifest.Entries.Count == 0)
            {
                Console.WriteLine("Looks like we are setting up your first account.");
                passKey = Manifest.PromptSetupPassKey(true);
            }
            else if (Manifest.Entries.Count > 0 && Manifest.Encrypted)
            {
                if (string.IsNullOrEmpty(passkey))
                {
                    passkey = Manifest.PromptForPassKey();
                }
            }

            //Save the file immediately; losing this would be bad.
            if (!Manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey))
            {
                Manifest.RemoveAccount(linker.LinkedAccount);
                Console.WriteLine("Unable to save mobile authenticator file. The mobile authenticator has not been linked.");
                return;
            }

            Console.WriteLine(
                $"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;
            do
            {
                Console.Write("Please input the SMS message sent to your phone number: ");
                string smsCode = Console.ReadLine();

                finalizeResponse = linker.FinalizeAddAuthenticator(smsCode);
                if (Verbose)
                {
                    Console.WriteLine(finalizeResponse);
                }

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

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    Console.WriteLine(
                        "Unable to generate the proper codes to finalize this authenticator. The authenticator should not have been linked.");
                    Console.WriteLine(
                        $"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);
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    Console.WriteLine("Unable to finalize this authenticator. The authenticator should not have been linked.");
                    Console.WriteLine(
                        $"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);
                    return;
                }
            } while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success);

            //Linked, finally. Re-save with FullyEnrolled property.
            Manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            Console.WriteLine(
                $"Mobile authenticator successfully linked. Please actually write down your revocation code: {linker.LinkedAccount.RevocationCode}");
        }
Example #14
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();
        }
Example #15
0
        private void btnSteamLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;

            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("此帐户已经有一个与其绑定的移动身份验证器。在添入新的验证器之前,请把您的Steam帐户从旧的验证器中删除。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadRSA:
                    MessageBox.Show("错误记录:Steam返回“BadRSA”。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show("错误记录:用户名或密码不正确。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show("错误记录:太多次失败的登录,稍后再试。", "Login Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show("错误记录:Steam返回“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("以下列格式输入您的电话号码:+{区号}电话号码。+86 12345678910");
                        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.MustConfirmEmail:
                    MessageBox.Show("Steam会先发一封确认添加手机号码的邮件,请先去点击邮件中的添加手机号码按钮,然后点击确认。");
                    break;

                case AuthenticatorLinker.LinkResult.GeneralFailure:
                    MessageBox.Show("添加电话号码时出错。Steam返回“GeneralFailure”。");
                    this.Close();
                    return;
                }
            }

            Manifest manifest = Manifest.GetManifest();
            string   passKey  = null;

            if (manifest.Entries.Count == 0)
            {
                passKey = manifest.PromptSetupPassKey("请输入加密密码。留下空白或点击取消不加密都非常不安全。");
            }
            else if (manifest.Entries.Count > 0 && manifest.Encrypted)
            {
                bool passKeyValid = false;
                while (!passKeyValid)
                {
                    InputForm passKeyForm = new InputForm("请输入您当前的加密密码。");
                    passKeyForm.ShowDialog();
                    if (!passKeyForm.Canceled)
                    {
                        passKey      = passKeyForm.txtBox.Text;
                        passKeyValid = manifest.VerifyPasskey(passKey);
                        if (!passKeyValid)
                        {
                            MessageBox.Show("此密码无效。请输入您用于其他帐户的密码。");
                        }
                    }
                    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("无法保存移动身份验证器文件。 移动身份验证器尚未连接。");
                this.Close();
                return;
            }

            MessageBox.Show("移动身份验证器尚未连接。 在最终确认使用桌面验证器之前,请写下您的撤销代码:" + linker.LinkedAccount.RevocationCode);

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success)
            {
                InputForm smsCodeForm = new InputForm("请输入发送到您手机的短信代码。");
                smsCodeForm.ShowDialog();
                if (smsCodeForm.Canceled)
                {
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;
                }

                InputForm confirmRevocationCode = new InputForm("请输入您的撤销代码,以确保您已保存它。");
                confirmRevocationCode.ShowDialog();
                if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode)
                {
                    MessageBox.Show("撤销代码不正确;无法连接桌面验证器。");
                    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("无法生成正确的代码来完成此身份验证器。 验证器没有被连接。 应该是偶发状况,请写下你的撤销代码,因为这是最后一次看到它的机会:" + linker.LinkedAccount.RevocationCode);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    this.Close();
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    MessageBox.Show("无法生成正确的代码来完成此身份验证器。 验证器没有被连接。 应该是偶发状况,请写下你的撤销代码,因为这是最后一次看到它的机会:" + 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("成功连接移动验证器。 请写下你的撤销代码:" + linker.LinkedAccount.RevocationCode);
            this.Close();
        }
Example #16
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);
        }
Example #17
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();
        }
Example #18
0
        public void LinkMobileAuth()
        {
            var login       = new UserLogin(loginInfo.Username, loginInfo.Password);
            var loginResult = login.DoLogin();

            if (loginResult == LoginResult.NeedEmail)
            {
                while (loginResult == LoginResult.NeedEmail)
                {
                    Console.WriteLine("Enter Steam Guard code from email :");
                    var emailCode = Console.ReadLine();
                    login.EmailCode = emailCode;
                    loginResult     = login.DoLogin();
                }
            }
            if (loginResult == SteamAuth.LoginResult.LoginOkay)
            {
                Console.WriteLine("Linking mobile authenticator...");
                var authLinker    = new SteamAuth.AuthenticatorLinker(login.Session);
                var addAuthResult = authLinker.AddAuthenticator();
                if (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.MustProvidePhoneNumber)
                {
                    while (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.MustProvidePhoneNumber)
                    {
                        Console.WriteLine("Enter phone number with country code, e.g. +1XXXXXXXXXXX :");
                        var phoneNumber = Console.ReadLine();
                        authLinker.PhoneNumber = phoneNumber;
                        addAuthResult          = authLinker.AddAuthenticator();
                    }
                }
                if (addAuthResult == SteamAuth.AuthenticatorLinker.LinkResult.AwaitingFinalization)
                {
                    steamGuardAccount = authLinker.LinkedAccount;
                    try
                    {
                        var authFile = String.Format("{0}.auth", loginInfo.Username);
                        Directory.CreateDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "authfiles"));
                        File.WriteAllText(authFile, Newtonsoft.Json.JsonConvert.SerializeObject(steamGuardAccount));
                        Console.WriteLine("Enter SMS code :");
                        var smsCode    = Console.ReadLine();
                        var authResult = authLinker.FinalizeAddAuthenticator(smsCode);
                        if (authResult == SteamAuth.AuthenticatorLinker.FinalizeResult.Success)
                        {
                            Console.WriteLine("Linked authenticator.");
                        }
                        else
                        {
                            Console.WriteLine("Error linking authenticator: " + authResult);
                        }
                    }
                    catch (IOException)
                    {
                        Console.WriteLine("Failed to save auth file. Aborting authentication.");
                    }
                }
                else
                {
                    Console.WriteLine("Error adding authenticator: " + addAuthResult);
                }
            }
            else
            {
                if (loginResult == SteamAuth.LoginResult.Need2FA)
                {
                    Console.WriteLine("Mobile authenticator has already been linked!");
                }
                else
                {
                    Console.WriteLine("Error performing mobile login: " + loginResult);
                }
            }
        }
Example #19
0
        private void SteamAuthLogin()
        {
            var         authLogin = new UserLogin(cfg.SteamLogin, cfg.SteamPassword);
            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:
                    Console.WriteLine("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);
        }
Example #20
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.");
            }
        }
Example #21
0
        private void LoginUser()
        {
            string       username = txtUsername.Text;
            SecureString password = txtPassword.SecurePassword;

            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(Properties.strings.LoginEnterEmailCode);
                    emailForm.ShowDialog(this);
                    if (emailForm.Canceled)
                    {
                        Close();
                        return;
                    }

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


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

                    userLogin.CaptchaText = captchaForm.Code;
                    break;

                case LoginResult.Need2FA:
                    MessageBox.Show(Properties.strings.LoginAleadLinked, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.BadRSA:
                    MessageBox.Show(Properties.strings.LoginBadRSA, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show(Properties.strings.LoginBadCreds, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show(Properties.strings.LoginTooManyFailedAttempts, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show(Properties.strings.LoginGeneralFailure, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    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(Properties.strings.LoginEnterPhoneNumber);
                        phoneNumberForm.txtBox.Text = "+1 ";
                        phoneNumberForm.ShowDialog(this);
                        if (phoneNumberForm.Canceled)
                        {
                            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(Properties.strings.LoginErrorAddingNumber);
                    Close();
                    return;
                }
            }

            Manifest     manifest = Manifest.GetManifest();
            SecureString passKey  = null;

            if (manifest.Entries.Count == 0)
            {
                passKey = manifest.PromptSetupPasskey(Properties.strings.LoginEnterPasskey);
            }
            else if (manifest.Entries.Count > 0 && manifest.Encrypted)
            {
                bool passKeyValid = false;
                while (!passKeyValid)
                {
                    InputForm passKeyForm = new InputForm(Properties.strings.ManifestEnterKey, true);
                    passKeyForm.ShowDialog(this);
                    if (!passKeyForm.Canceled)
                    {
                        passKey      = passKeyForm.GetPassword();
                        passKeyValid = manifest.VerifyPasskey(passKey);
                        if (!passKeyValid)
                        {
                            MessageBox.Show(Properties.strings.LoginInvaildPasskey);
                        }
                    }
                    else
                    {
                        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(Properties.strings.LoginUnableToSaveFile);
                Close();
                return;
            }

            MessageBox.Show(String.Format(Properties.strings.LoginWriteRevocation, linker.LinkedAccount.RevocationCode));

            AuthenticatorLinker.FinalizeResult finalizeResponse = AuthenticatorLinker.FinalizeResult.GeneralFailure;
            while (finalizeResponse != AuthenticatorLinker.FinalizeResult.Success)
            {
                InputForm smsCodeForm = new InputForm(Properties.strings.LoginEnterSMS);
                smsCodeForm.ShowDialog(this);
                if (smsCodeForm.Canceled)
                {
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;
                }

                InputForm confirmRevocationCode = new InputForm(Properties.strings.LoginEnterRevocation);
                confirmRevocationCode.ShowDialog(this);
                if (confirmRevocationCode.txtBox.Text.ToUpper() != linker.LinkedAccount.RevocationCode)
                {
                    MessageBox.Show(Properties.strings.LoginRevocationIncorrect);
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;
                }

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

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

                case AuthenticatorLinker.FinalizeResult.UnableToGenerateCorrectCodes:
                    MessageBox.Show(String.Format(Properties.strings.LoginUnableToGenerateCodes, linker.LinkedAccount.RevocationCode));
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;

                case AuthenticatorLinker.FinalizeResult.GeneralFailure:
                    MessageBox.Show(String.Format(Properties.strings.LoginUnableToFinalize, linker.LinkedAccount.RevocationCode));
                    manifest.RemoveAccount(linker.LinkedAccount);
                    Close();
                    return;
                }
            }

            //Linked, finally. Re-save with FullyEnrolled property.
            manifest.SaveAccount(linker.LinkedAccount, passKey != null, passKey);
            MessageBox.Show(String.Format(Properties.strings.LoginSuccessfulAdd, linker.LinkedAccount.RevocationCode));
            Close();
        }
Example #22
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, SecureString 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(Properties.strings.LoginEnterEmailCode);
                    emailForm.ShowDialog(this);
                    if (emailForm.Canceled)
                    {
                        Close();
                        return;
                    }

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

                case LoginResult.NeedCaptcha:
                    Captcha captchaForm = new Captcha(mUserLogin.CaptchaGID);
                    captchaForm.ShowDialog();
                    if (captchaForm.Canceled)
                    {
                        Close();
                        return;
                    }

                    mUserLogin.CaptchaText = captchaForm.Code;
                    break;

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

                case LoginResult.BadRSA:
                    MessageBox.Show(Properties.strings.LoginBadRSA, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.BadCredentials:
                    MessageBox.Show(Properties.strings.LoginBadCreds, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.TooManyFailedLogins:
                    MessageBox.Show(Properties.strings.LoginTooManyFailedAttempts, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;

                case LoginResult.GeneralFailure:
                    MessageBox.Show(Properties.strings.LoginGeneralFailure, Properties.strings.LoginErrorT, MessageBoxButton.OK, MessageBoxImage.Error);
                    Close();
                    return;
                }
            }

            androidAccount.Session = mUserLogin.Session;

            HandleManifest(man);
        }