41 releases (23 stable)

7.3.1 Nov 11, 2023
7.2.0 Nov 26, 2022
7.1.0 Oct 20, 2022
7.0.0 Jul 12, 2022
0.0.2 Mar 4, 2015

#4 in Authentication

Download history 137957/week @ 2024-01-13 141639/week @ 2024-01-20 155493/week @ 2024-01-27 144464/week @ 2024-02-03 145936/week @ 2024-02-10 145300/week @ 2024-02-17 157417/week @ 2024-02-24 155711/week @ 2024-03-02 155142/week @ 2024-03-09 166608/week @ 2024-03-16 155644/week @ 2024-03-23 203544/week @ 2024-03-30 183949/week @ 2024-04-06 169162/week @ 2024-04-13 169009/week @ 2024-04-20 130458/week @ 2024-04-27

695,452 downloads per month
Used in 1,030 crates (400 directly)

Apache-2.0

13KB
190 lines

Rustastic Password

rpassword makes it easy to read passwords in a console application on all platforms, Unix, Windows, WASM, etc.

rpassword is made available free of charge. You can support its development through Liberapay 💪

Usage

Add rpassword as a dependency in Cargo.toml:

[dependencies]
rpassword = "7.3"

See examples and docs at https://docs.rs/rpassword.

License

The source code is released under the Apache 2.0 license.


lib.rs:

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);

Finally, in unit tests, you might want to pass a Cursor, which implements BufRead. In that case, you can use read_password_from_bufread and prompt_password_from_bufread:

use std::io::Cursor;

let mut mock_input = Cursor::new("my-password\n".as_bytes().to_owned());
let password = rpassword::read_password_from_bufread(&mut mock_input).unwrap();
println!("Your password is {}", password);

let mut mock_input = Cursor::new("my-password\n".as_bytes().to_owned());
let mut mock_output = Cursor::new(Vec::new());
let password = rpassword::prompt_password_from_bufread(&mut mock_input, &mut mock_output, "Your password: ").unwrap();
println!("Your password is {}", password);

Dependencies

~0–12MB
~88K SLoC