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.
The library also includes a new
function for creating a new PasswordReader + IsInteractive
instance.
§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;
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 + IsInteractive
traits. Alternatively, instantiate with yapp::Yapp::default()
to use the
concrete struct type.
See examples for more.
Structs§
- An implementation of the
PasswordReader
trait.
Traits§
- A trait providing interactivity check for
Yapp
- A trait for reading passwords from the user.
Functions§
- Creates a new password reader. Returns an instance of
PasswordReader
trait.