From a65c972116daa16efc6b4d7d355fcec9b342dd28 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 19 Apr 2020 05:19:02 -0400 Subject: implement history command to get password history --- src/bin/rbw/commands.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/bin/rbw/commands.rs') diff --git a/src/bin/rbw/commands.rs b/src/bin/rbw/commands.rs index 7152a59..81ea2e2 100644 --- a/src/bin/rbw/commands.rs +++ b/src/bin/rbw/commands.rs @@ -299,6 +299,30 @@ pub fn remove(name: &str, username: Option<&str>) -> anyhow::Result<()> { Ok(()) } +pub fn history(name: &str, username: Option<&str>) -> anyhow::Result<()> { + unlock()?; + + let email = config_email()?; + let db = rbw::db::Db::load(&email) + .context("failed to load password database")?; + + let desc = format!( + "{}{}", + username + .map(|s| format!("{}@", s)) + .unwrap_or_else(|| "".to_string()), + name + ); + + let (_, decrypted) = find_entry(&db, name, username) + .with_context(|| format!("couldn't find entry for '{}'", desc))?; + for history in decrypted.history { + println!("{}: {}", history.last_used_date, history.password); + } + + Ok(()) +} + pub fn lock() -> anyhow::Result<()> { ensure_agent()?; crate::actions::lock()?; -- cgit v1.2.3-54-g00ecf