inplace/
inplace.rs

1// Copyright 2025 Steven Dee.
2//
3// This project is made available under a BSD-compatible license. See the
4// LICENSE file in the project root for details.
5//
6// The readpassphrase source and header are copyright 2000-2002, 2007, 2010
7// Todd C. Miller.
8
9use std::process::exit;
10
11use readpassphrase_3::{readpassphrase, Flags as RpFlags, PASSWORD_LEN};
12use zeroize::Zeroizing;
13
14fn main() {
15    let mut buf = Zeroizing::new(vec![0u8; PASSWORD_LEN]);
16    let password = Zeroizing::new(
17        readpassphrase(c"Password: ", &mut buf, RpFlags::empty())
18            .expect("failed reading passphrase")
19            .to_string(),
20    );
21    for _ in 0..5 {
22        let confirm = readpassphrase(c"Confirmation: ", &mut buf, RpFlags::REQUIRE_TTY)
23            .expect("failed reading confirmation");
24        if *password == confirm {
25            eprintln!("Passwords match.");
26            return;
27        }
28        eprintln!("Passwords don’t match.");
29    }
30    eprintln!("Too many attempts.");
31    exit(1);
32}