getpass

Function getpass 

Source
pub fn getpass(prompt: &CStr) -> Result<String, Error>
Expand description

Reads a passphrase using readpassphrase(3), returning a String.

Internally, this function uses a buffer of PASSWORD_LEN bytes, allowing for passwords up to PASSWORD_LEN - 1 characters (accounting for the C null terminator.) If the entered passphrase is longer, it will be truncated to the maximum length.

§Security

The returned String is owned by the caller, and therefore it is the caller’s responsibility to clear it when you are done with it:

let mut pass = getpass(c"Pass: ")?;
_ = pass;
pass.zeroize();
Examples found in repository?
examples/pass.rs (line 12)
11fn main() {
12    let mut password = getpass(c"Password: ").expect("failed reading password");
13    println!("{password}");
14    password.zeroize();
15}