hide password

This commit is contained in:
Mylloon 2023-01-13 20:55:00 +01:00
parent bce24919eb
commit c1925894f7
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
4 changed files with 38 additions and 8 deletions

22
Cargo.lock generated
View file

@ -1138,6 +1138,27 @@ dependencies = [
"winreg",
]
[[package]]
name = "rpassword"
version = "7.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6678cf63ab3491898c0d021b493c94c9b221d91295294a2a5746eacbe5928322"
dependencies = [
"libc",
"rtoolbox",
"winapi",
]
[[package]]
name = "rtoolbox"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "034e22c514f5c0cb8a10ff341b9b048b5ceb21591f31c8f44c43b960f9b3524a"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "rustc_version"
version = "0.4.0"
@ -1638,6 +1659,7 @@ dependencies = [
"clap",
"directories",
"reqwest",
"rpassword",
"scraper",
"serde",
"tokio",

View file

@ -16,3 +16,4 @@ reqwest = { version = "0.11", features = ["cookies"] }
tokio = { version = ">=1.23.1", features = ["full"] }
scraper = "0.14"
clap = { version = "4.0.32", features = ["derive"] }
rpassword = "7.2"

View file

@ -45,9 +45,9 @@ async fn main() {
username: if args.username.is_some() {
args.username.unwrap()
} else {
utils::ask("Username: ")
utils::ask_username()
},
password: Some(utils::ask("Password: ")),
password: Some(utils::ask_password()),
}
}
},
@ -57,14 +57,14 @@ async fn main() {
args.username.unwrap()
} else {
// Only ask if nothing has been given in args
utils::ask("Username: ")
utils::ask_username()
},
password: Some(utils::ask("Password: ")),
password: Some(utils::ask_password()),
},
};
if config.password.is_none() {
config.password = Some(utils::ask("Password: "));
config.password = Some(utils::ask_password());
}
let user_agent = format!("uwm/{}", env!("CARGO_PKG_VERSION"));

View file

@ -1,17 +1,24 @@
use std::io::{self, Write};
/// Ask user for something
pub fn ask(text: &str) -> std::string::String {
/// Ask user for username
pub fn ask_username() -> std::string::String {
let mut user_input = String::new();
let stdin = io::stdin();
print!("{}", text);
print!("Username: ");
io::stdout().flush().unwrap();
stdin.read_line(&mut user_input).unwrap();
user_input.trim_end().to_string()
}
/// Ask user for password
pub fn ask_password() -> std::string::String {
print!("Password: ");
io::stdout().flush().unwrap();
rpassword::read_password().unwrap()
}
/// Write a document to a file
///
/// `html_data` may be created with something like that: