8 releases (4 breaking)

0.5.0 Mar 2, 2025
0.4.1 Mar 27, 2024
0.3.0 Mar 25, 2024
0.2.0 Mar 25, 2024
0.1.2 Mar 25, 2024

#298 in Authentication

Download history 14/week @ 2024-11-17 12/week @ 2024-11-24 24/week @ 2024-12-01 46/week @ 2024-12-08 36/week @ 2024-12-15 1/week @ 2024-12-22 9/week @ 2025-01-05 9/week @ 2025-01-12 1/week @ 2025-01-19 16/week @ 2025-02-02 47/week @ 2025-02-09 26/week @ 2025-02-16 3/week @ 2025-02-23 145/week @ 2025-03-02

227 downloads per month
Used in syno-photos-util

MIT license

16KB
262 lines

YAPP

Crates.io Version

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.

Features

  • 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 (optionally PasswordReader + 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);
}
use yapp::PasswordReader;

fn my_func(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);
}

See examples for more.

Dependencies

~1.6–8MB
~57K SLoC