feat: Support export and import with different password #30
3 changed files with 7 additions and 4 deletions
|
@ -38,7 +38,7 @@ pub struct Add {
|
|||
|
||||
impl LprsCommand for Add {
|
||||
fn run(mut self, mut vault_manager: Vaults) -> LprsResult<()> {
|
||||
self.vault_info.password = utils::user_password(self.password)?;
|
||||
self.vault_info.password = utils::user_password(self.password, "Vault password:")?;
|
||||
vault_manager.add_vault(self.vault_info);
|
||||
vault_manager.try_export()
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ impl LprsCommand for Edit {
|
|||
*vault = Vault::new(
|
||||
self.name.as_ref().unwrap_or(&vault.name),
|
||||
self.username.as_ref().or(vault.username.as_ref()),
|
||||
utils::user_password(self.password)?
|
||||
utils::user_password(self.password, "New vault password:")?
|
||||
.as_ref()
|
||||
.or(vault.password.as_ref()),
|
||||
self.service.as_ref().or(vault.service.as_ref()),
|
||||
|
|
|
@ -52,14 +52,17 @@ pub fn local_project_file(filename: &str) -> LprsResult<PathBuf> {
|
|||
///
|
||||
/// ## Errors
|
||||
/// - When failed to get the password from stdin
|
||||
pub fn user_password(password: Option<Option<String>>) -> LprsResult<Option<String>> {
|
||||
pub fn user_password(
|
||||
password: Option<Option<String>>,
|
||||
prompt_message: &str,
|
||||
) -> LprsResult<Option<String>> {
|
||||
Ok(match password {
|
||||
None => None,
|
||||
Some(Some(p)) => Some(p),
|
||||
Some(None) => {
|
||||
log::debug!("User didn't provide a password, prompting it");
|
||||
Some(
|
||||
Password::new("Vault password:")
|
||||
Password::new(prompt_message)
|
||||
.without_confirmation()
|
||||
.with_formatter(&|p| "*".repeat(p.chars().count()))
|
||||
.with_display_mode(PasswordDisplayMode::Masked)
|
||||
|
|
Loading…
Reference in a new issue