inplace/
inplace.rs

1use std::process::exit;
2
3use readpassphrase_3::{readpassphrase, Flags as RpFlags, PASSWORD_LEN};
4use zeroize::Zeroizing;
5
6fn main() {
7    let mut buf = Zeroizing::new(vec![0u8; PASSWORD_LEN]);
8    let password = Zeroizing::new(
9        readpassphrase(c"Password: ", &mut buf, RpFlags::empty())
10            .expect("failed reading passphrase")
11            .to_string(),
12    );
13    for _ in 0..5 {
14        let confirm = readpassphrase(c"Confirmation: ", &mut buf, RpFlags::REQUIRE_TTY)
15            .expect("failed reading confirmation");
16        if *password == confirm {
17            eprintln!("Passwords match.");
18            return;
19        }
20        eprintln!("Passwords don’t match.");
21    }
22    eprintln!("Too many attempts.");
23    exit(1);
24}