refactor setup login, add captcha support

This commit is contained in:
“Carson 2020-10-12 12:38:22 -04:00
parent 972677f515
commit 812683c624

View file

@ -364,29 +364,40 @@ namespace SteamGuard
var password = Utils.ReadLineSecure(); var password = Utils.ReadLineSecure();
UserLogin login = new UserLogin(username, password); UserLogin login = new UserLogin(username, password);
string emailCode = null, twoFactorCode = null; LoginResult loginResult;
while (true) do
{ {
login.EmailCode = emailCode;
login.TwoFactorCode = twoFactorCode;
Console.Write($"Logging in {username}... "); Console.Write($"Logging in {username}... ");
LoginResult loginResult = login.DoLogin(); loginResult = login.DoLogin();
Console.WriteLine(loginResult); Console.WriteLine(loginResult);
if (loginResult == LoginResult.NeedEmail) switch (loginResult)
{ {
Console.Write("Email code: "); case LoginResult.NeedEmail:
emailCode = Console.ReadLine(); Console.Write("Email code: ");
continue; login.EmailCode = Console.ReadLine();
break;
case LoginResult.Need2FA:
Console.Write("2FA code: ");
login.TwoFactorCode = Console.ReadLine();
break;
case LoginResult.NeedCaptcha:
Console.WriteLine($"Please open: https://steamcommunity.com/public/captcha.php?gid={login.CaptchaGID}");
Console.Write("Captcha text: ");
login.CaptchaText = Console.ReadLine();
break;
case LoginResult.BadCredentials:
Console.WriteLine("error: Bad Credentials");
return;
case LoginResult.TooManyFailedLogins:
Console.WriteLine("error: Too many failed logins. Wait a bit before trying again.");
return;
case LoginResult.LoginOkay:
break;
default:
Console.WriteLine($"Unknown login result: {loginResult}");
break;
} }
else if (loginResult == LoginResult.Need2FA) } while (loginResult != LoginResult.LoginOkay);
{
Console.Write("2FA code: ");
twoFactorCode = Console.ReadLine();
continue;
}
if (!login.LoggedIn) return;
break;
}
AuthenticatorLinker linker = new AuthenticatorLinker(login.Session); AuthenticatorLinker linker = new AuthenticatorLinker(login.Session);
AuthenticatorLinker.LinkResult linkResult = AuthenticatorLinker.LinkResult.GeneralFailure; AuthenticatorLinker.LinkResult linkResult = AuthenticatorLinker.LinkResult.GeneralFailure;