Expand description
§Yet Another Password Prompt
A library for reading passwords from the user.
This library provides a PasswordReader
trait for reading passwords from the user, and
IsInteractive
trait for checking if terminal is attended by the user or e.g. ran as a
background service.
It includes a default implementation of the PasswordReader
and IsInteractive
traits, Yapp
,
which can read passwords from an interactive terminal or from standard input.
§Features
- Reads user passwords from the input, optionally with a prompt and
echoing replacement symbols (
*
, or another of your choice). - Reads passwords interactively or non-interactively (e.g. when input is redirected through a pipe).
- 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
console
library underneath, it handles Unicode correctly (tested on Windows and Linux).
§Usage Example
use yapp::{PasswordReader, Yapp};
fn my_func<P: PasswordReader>(yapp: &mut P) {
let password = yapp.read_password_with_prompt("Type your password: ").unwrap();
println!("You typed: {password}");
}
fn my_func_dyn(yapp: &mut dyn PasswordReader) {
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);
my_func_dyn(&mut yapp);
}
See examples for more.
Structs§
- Yapp
- An implementation of the
PasswordReader
trait.
Traits§
- IsInteractive
- A trait providing interactivity check for
Yapp
- Password
Reader - A trait for reading passwords from the user.