From 4b15b9403abe4b6ffc820db60e0f43d8b88287bc Mon Sep 17 00:00:00 2001 From: TheAwiteb Date: Sun, 24 Dec 2023 20:26:51 +0300 Subject: [PATCH] Don't ask for master password in clean command --- src/cli/mod.rs | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 292af26..8090fca 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -63,26 +63,33 @@ impl Cli { "Getting password file: {}", passwords_file.to_string_lossy() ); - let password = scanpw::scanpw!("Master Password: "); - - if password::is_new_password_file(&passwords_file)? { - let analyzed = passwords::analyzer::analyze(&password); - if analyzed.length() < 15 { - return Err(PassrsError::WeakPassword( - "The password length must be beggier then 15".to_owned(), - )); - } else if passwords::scorer::score(&analyzed) < 80.0 { - return Err(PassrsError::WeakPassword( - "Your password is not stronge enough".to_owned(), - )); + let password_manager = if matches!(self.command, Commands::Clean(..)) { + Passwords { + passwords_file, + ..Default::default() } - } + } else { + let password = scanpw::scanpw!("Master Password: "); - let master_password = sha256::digest(password); - let password_manager = Passwords::try_reload( - passwords_file, - master_password.into_bytes().into_iter().take(32).collect(), - )?; + if password::is_new_password_file(&passwords_file)? { + let analyzed = passwords::analyzer::analyze(&password); + if analyzed.length() < 15 { + return Err(PassrsError::WeakPassword( + "The password length must be beggier then 15".to_owned(), + )); + } else if passwords::scorer::score(&analyzed) < 80.0 { + return Err(PassrsError::WeakPassword( + "Your password is not stronge enough".to_owned(), + )); + } + } + + let master_password = sha256::digest(password); + Passwords::try_reload( + passwords_file, + master_password.into_bytes().into_iter().take(32).collect(), + )? + }; self.command.run(password_manager)?; Ok(())