Skip to content

Commit

Permalink
using dialoguer for prompting new password
Browse files Browse the repository at this point in the history
  • Loading branch information
Aderemi-Adesada committed Jun 24, 2023
1 parent 1d3fee3 commit b1a006e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 35 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ merge = { workspace = true }
directories = { workspace = true }
nom = { workspace = true }
rpassword = { workspace = true }
dialoguer = "0.10.4"
bytesize = { workspace = true }
indicatif = { workspace = true }
path-dedot = { workspace = true }
Expand Down
24 changes: 7 additions & 17 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use anyhow::{bail, Result};
use crate::{commands::get_repository, Application, RUSTIC_APP};

use bytes::Bytes;
use rpassword::prompt_password;
use dialoguer::Password;

use rustic_core::{
hash, random_poly, ConfigFile, DecryptBackend, DecryptWriteBackend, FileType, Id, Key, KeyFile,
Expand Down Expand Up @@ -81,28 +81,18 @@ pub(crate) fn save_config(

let pass = password.map_or_else(
|| -> String {
let password_initial = match prompt_password("enter password for new key: ") {
Ok(password) => password,
Err(err) => {
status_err!("{}", err);
RUSTIC_APP.shutdown(Shutdown::Crash);
}
};
let password_result = Password::new().with_prompt("enter password for new key")
.with_confirmation("confirm password", "passwords do not match")
.interact();

let password_confirm = match prompt_password("confirm password: ") {
Ok(password) => password,
let password = match password_result {
Ok(it) => it,
Err(err) => {
status_err!("{}", err);
RUSTIC_APP.shutdown(Shutdown::Crash);
}
};

if password_initial != password_confirm {
status_err!("Fatal: passwords do not match");
RUSTIC_APP.shutdown(Shutdown::Crash);
}

password_initial
password
},
|pass| pass,
);
Expand Down
27 changes: 9 additions & 18 deletions src/commands/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use anyhow::Result;

use std::{fs::File, io::BufReader};

use rpassword::{prompt_password, read_password_from_bufread};
use rpassword::read_password_from_bufread;
use dialoguer::Password;

use rustic_core::{hash, FileType, KeyFile, WriteBackend};

Expand Down Expand Up @@ -80,28 +81,18 @@ impl AddCmd {

let pass = self.new_password_file.as_ref().map_or_else(
|| -> String {
let password_initial = match prompt_password("enter password for new key: ") {
Ok(password) => password,
Err(err) => {
status_err!("{}", err);
RUSTIC_APP.shutdown(Shutdown::Crash);
}
};

let password_confirm = match prompt_password("confirm password: ") {
Ok(password) => password,
let password_result = Password::new().with_prompt("enter password for new key")
.with_confirmation("confirm password", "passwords do not match")
.interact();

let password = match password_result {
Ok(it) => it,
Err(err) => {
status_err!("{}", err);
RUSTIC_APP.shutdown(Shutdown::Crash);
}
};

if password_initial != password_confirm {
status_err!("Fatal: passwords do not match");
RUSTIC_APP.shutdown(Shutdown::Crash);
}

password_initial
password
},
|file| {
let mut file = BufReader::new(match File::open(file) {
Expand Down

0 comments on commit b1a006e

Please sign in to comment.