login: make the 2fa and email code prompts less easy to mess up (#352)
This commit is contained in:
parent
68dcedaeb7
commit
4ea44151b9
1 changed files with 41 additions and 13 deletions
54
src/login.rs
54
src/login.rs
|
@ -8,6 +8,7 @@ use steamguard::{
|
||||||
steamapi::{self, AuthenticationClient},
|
steamapi::{self, AuthenticationClient},
|
||||||
token::Tokens,
|
token::Tokens,
|
||||||
transport::Transport,
|
transport::Transport,
|
||||||
|
userlogin::UpdateAuthSessionError,
|
||||||
DeviceDetails, LoginError, SteamGuardAccount, UserLogin,
|
DeviceDetails, LoginError, SteamGuardAccount, UserLogin,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -141,21 +142,48 @@ fn do_login_impl<T: Transport + Clone>(
|
||||||
eprintln!("Press enter when you have confirmed.");
|
eprintln!("Press enter when you have confirmed.");
|
||||||
tui::pause();
|
tui::pause();
|
||||||
}
|
}
|
||||||
EAuthSessionGuardType::k_EAuthSessionGuardType_DeviceCode => {
|
EAuthSessionGuardType::k_EAuthSessionGuardType_DeviceCode
|
||||||
let code = if let Some(account) = account {
|
| EAuthSessionGuardType::k_EAuthSessionGuardType_EmailCode => {
|
||||||
debug!("Generating 2fa code...");
|
let prompt = if method.confirmation_type
|
||||||
let time = steamapi::get_server_time(transport)?.server_time();
|
== EAuthSessionGuardType::k_EAuthSessionGuardType_DeviceCode
|
||||||
account.generate_code(time)
|
{
|
||||||
|
"Enter the 2fa code from your device: "
|
||||||
} else {
|
} else {
|
||||||
eprint!("Enter the 2fa code from your device: ");
|
"Enter the 2fa code sent to your email: "
|
||||||
tui::prompt().trim().to_owned()
|
|
||||||
};
|
};
|
||||||
login.submit_steam_guard_code(method.confirmation_type, code)?;
|
let mut attempts = 0;
|
||||||
}
|
loop {
|
||||||
EAuthSessionGuardType::k_EAuthSessionGuardType_EmailCode => {
|
let code = if let Some(account) = account {
|
||||||
eprint!("Enter the 2fa code sent to your email: ");
|
debug!("Generating 2fa code...");
|
||||||
let code = tui::prompt().trim().to_owned();
|
let time = steamapi::get_server_time(transport.clone())?.server_time();
|
||||||
login.submit_steam_guard_code(method.confirmation_type, code)?;
|
account.generate_code(time)
|
||||||
|
} else {
|
||||||
|
tui::prompt_non_empty(prompt).trim().to_owned()
|
||||||
|
};
|
||||||
|
|
||||||
|
match login.submit_steam_guard_code(method.confirmation_type, code) {
|
||||||
|
Ok(_) => break,
|
||||||
|
Err(err) => {
|
||||||
|
error!("Failed to submit code: {}", err);
|
||||||
|
|
||||||
|
match err {
|
||||||
|
UpdateAuthSessionError::TooManyAttempts
|
||||||
|
| UpdateAuthSessionError::SessionExpired
|
||||||
|
| UpdateAuthSessionError::InvalidGuardType => {
|
||||||
|
error!("Error is unrecoverable. Aborting.");
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
attempts += 1;
|
||||||
|
debug!("Attempts: {}/3", attempts);
|
||||||
|
if attempts >= 3 {
|
||||||
|
error!("Too many failed attempts. Aborting.");
|
||||||
|
return Err(err.into());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
EAuthSessionGuardType::k_EAuthSessionGuardType_None => {
|
EAuthSessionGuardType::k_EAuthSessionGuardType_None => {
|
||||||
debug!("No login confirmation required. Proceeding with login.");
|
debug!("No login confirmation required. Proceeding with login.");
|
||||||
|
|
Loading…
Reference in a new issue