aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/rbw/commands.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2020-04-19 05:19:02 -0400
committerJesse Luehrs <doy@tozt.net>2020-04-19 05:19:02 -0400
commita65c972116daa16efc6b4d7d355fcec9b342dd28 (patch)
tree4892293b557cd922d648ceba74df07fd90c0a12d /src/bin/rbw/commands.rs
parent988296d6c9e053d632ee5610ba3432a02776b132 (diff)
downloadrbw-a65c972116daa16efc6b4d7d355fcec9b342dd28.tar.gz
rbw-a65c972116daa16efc6b4d7d355fcec9b342dd28.zip
implement history command to get password history
Diffstat (limited to 'src/bin/rbw/commands.rs')
-rw-r--r--src/bin/rbw/commands.rs24
1 files changed, 24 insertions, 0 deletions
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()?;