Update: you can use the rpassword crate. Quoting from the README:
Add the rpassword
crate to your Cargo.toml
:
[dependencies]
rpassword = "0.0.4"
Then use the read_password()
function:
extern crate rpassword;
use rpassword::read_password;
use std::io::Write;
fn main() {
print!("Type a password: ");
std::io::stdout().flush().unwrap();
let password = read_password().unwrap();
println!("The password is: '{}'", password);
}
Old answer
I suspect your best bet is calling some C functions from rust: either getpass (3) or its recommended alternatives (see
Getting a password in C without using getpass). The tricky thing is that it differs by platform, of course (if you get it working, it'd be handy as a crate).
Depending on your requirements, you could also try using ncurses-rs (crate "ncurses"); I haven't tested it but it looks like example 2 might demo turning off echoing input.