Expand description
This library makes it easy to read passwords in a console application on all platforms, Unix, Windows, WASM, etc.
Here’s how you can read a password:
let password = rpassword::read_password().unwrap();
println!("Your password is {}", password);You can also prompt for a password:
let password = rpassword::prompt_password("Your password: ").unwrap();
println!("Your password is {}", password);For testing or custom use-cases, you can use read_password_with_config and prompt_password_with_config:
use std::io::{Cursor, Write};
let config = rpassword::ConfigBuilder::new()
// Default input is the console, but we can pass any file path or raw data
.input_data("my-password\n")
// Default output is the console, but we can also discard it
.output_discard()
// Default behavior is to hide the password as it's being typed, but we can change that
.password_feedback_mask('*')
.build();
let password = rpassword::read_password_with_config(config).unwrap();
println!("Your password is {}", password);Structs§
- Config
- Configuration for prompting and reading a password.
- Config
Builder - A builder for creating a
Config.
Functions§
- prompt_
password - Prompts on the TTY and then reads a password from TTY
- prompt_
password_ from_ bufread Deprecated - Prompts on
impl Writeand then reads a password fromimpl BufRead. - prompt_
password_ with_ config - Prompts and then reads a password using the given config
- read_
password - Reads a password from the TTY
- read_
password_ from_ bufread Deprecated - Reads a password from
impl BufRead. - read_
password_ with_ config - Reads a password from TTY using the given config