42 releases (24 stable)

7.4.0 Apr 20, 2025
7.3.1 Nov 11, 2023
7.2.0 Nov 26, 2022
7.0.0 Jul 12, 2022
0.0.2 Mar 4, 2015

#3 in Authentication

Download history 200303/week @ 2025-01-13 183406/week @ 2025-01-20 186292/week @ 2025-01-27 220034/week @ 2025-02-03 231296/week @ 2025-02-10 194929/week @ 2025-02-17 210042/week @ 2025-02-24 205980/week @ 2025-03-03 219729/week @ 2025-03-10 235045/week @ 2025-03-17 245673/week @ 2025-03-24 248175/week @ 2025-03-31 247616/week @ 2025-04-07 188943/week @ 2025-04-14 216763/week @ 2025-04-21 217234/week @ 2025-04-28

886,813 downloads per month
Used in 1,273 crates (506 directly)

Apache-2.0

125KB
190 lines

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

Rustastic Password

rpassword makes it easy to read passwords from Rust code in console applications on all platforms, Unix, Windows, WASM and more. It's similar to Linux's C function getpass() or Python's getpass module.

rpassword logo and headline

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.4"

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

License

The source code is released under the Apache 2.0 license.

Dependencies

~0–7.5MB
~53K SLoC