multiverse: hide the password by using rpassword to prompt it

This commit is contained in:
Benjamin Bouvier 2024-03-08 17:44:55 +01:00
parent e57a02fd91
commit 4ad79d6d44
3 changed files with 25 additions and 6 deletions

22
Cargo.lock generated
View File

@ -3553,6 +3553,7 @@ dependencies = [
"matrix-sdk",
"matrix-sdk-ui",
"ratatui",
"rpassword",
"serde_json",
"tokio",
"tracing",
@ -4827,6 +4828,17 @@ dependencies = [
"serde",
]
[[package]]
name = "rpassword"
version = "7.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80472be3c897911d0137b2d2b9055faf6eeac5b14e324073d83bc17b191d7e3f"
dependencies = [
"libc",
"rtoolbox",
"windows-sys 0.48.0",
]
[[package]]
name = "rsa"
version = "0.9.6"
@ -4847,6 +4859,16 @@ dependencies = [
"zeroize",
]
[[package]]
name = "rtoolbox"
version = "0.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c247d24e63230cdb56463ae328478bd5eac8b8faa8c69461a77e8e323afac90e"
dependencies = [
"libc",
"windows-sys 0.48.0",
]
[[package]]
name = "ruma"
version = "0.9.4"

View File

@ -17,6 +17,7 @@ imbl = { workspace = true }
matrix-sdk = { path = "../../crates/matrix-sdk", features = ["sso-login"] }
matrix-sdk-ui = { path = "../../crates/matrix-sdk-ui" }
ratatui = "0.26.1"
rpassword = "7.3.1"
serde_json = { workspace = true }
tokio = { version = "1.24.2", features = ["macros", "rt-multi-thread"] }
tracing = { workspace = true }

View File

@ -843,13 +843,9 @@ async fn login_with_password(client: &Client) -> anyhow::Result<()> {
io::stdin().read_line(&mut username).expect("Unable to read user input");
username = username.trim().to_owned();
print!("Password: ");
stdout().flush().expect("Unable to write to stdout");
let mut password = String::new();
io::stdin().read_line(&mut password).expect("Unable to read user input");
password = password.trim().to_owned();
let password = rpassword::prompt_password("Password.")?;
match client.matrix_auth().login_username(&username, &password).await {
match client.matrix_auth().login_username(&username, password.trim()).await {
Ok(_) => {
println!("Logged in as {username}");
break;