Yet Another Password Prompt
yapp is a small library create for Rust based on the
console to provide simple,
testable password prompt for CLI apps.
- Reads user passwords from the input, optionally with a prompt and
echoing replacement symbols (
*, or another of your choice). - Reads passwords interactively:
cargo run --example simple
- Reads passwords non-interactively:
echo "P@55w0rd\n" | cargo run --example simple
- Using the
PasswordReader(optionallyPasswordReader + IsInteractive) trait in your code allows for mocking the entire library in tests (see an example1 and example2) - Thanks to using the
consolelibrary underneath, it handles unicode correctly (tested on Windows and Linux).
use yapp::PasswordReader;
fn my_func<P: PasswordReader>(yapp: &mut P) {
let password = yapp.read_password_with_prompt("Type your password: ").unwrap();
println!("You typed: {password}");
}
fn main() {
let mut yapp = yapp::new().with_echo_symbol('*');
my_func(&mut yapp);
}The yapp::new() function returns an instance of PasswordReader
trait. Alternatively, instantiate with yapp::Yapp::default() to use
the concrete struct type.
See examples for more.