Skip to main content

Crate rpassword

Crate rpassword 

Source
Expand description

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

For testing or custom use-cases, you can use read_password_with_config and prompt_password_with_config:

use std::io::{Cursor, Write};

let config = rpassword::ConfigBuilder::new()
    // Default input is the console, but we can pass any file path or raw data
    .input_data("my-password\n")
    // Default output is the console, but we can also discard it
    .output_discard()
    // Default behavior is to hide the password as it's being typed, but we can change that
    .password_feedback_mask('*')
    .build();

let password = rpassword::read_password_with_config(config).unwrap();
println!("Your password is {}", password);

Structs§

Config
Configuration for prompting and reading a password.
ConfigBuilder
A builder for creating a Config.

Functions§

prompt_password
Prompts on the TTY and then reads a password from TTY
prompt_password_from_bufreadDeprecated
Prompts on impl Write and then reads a password from impl BufRead.
prompt_password_with_config
Prompts and then reads a password using the given config
read_password
Reads a password from the TTY
read_password_from_bufreadDeprecated
Reads a password from impl BufRead.
read_password_with_config
Reads a password from TTY using the given config