vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit 781056152a4b8e5b6bc70031aafd65bf9d59fd1c
parent b82710eecfd660996a7c75210a86125c7114af45
Author: Kumar Ankur <kmrankur@outlook.com>
Date:   Tue, 28 Aug 2018 02:38:58 +0530

Support password history #155 (#156)

* Password History Support (#155)

* down.sql logic not required as per review comments
Diffstat:
Amigrations/2018-08-27-172114_update_ciphers/down.sql | 0
Amigrations/2018-08-27-172114_update_ciphers/up.sql | 4++++
Msrc/api/core/ciphers.rs | 4++++
Msrc/db/models/cipher.rs | 8++++++++
Msrc/db/schema.rs | 1+
5 files changed, 17 insertions(+), 0 deletions(-)

diff --git a/migrations/2018-08-27-172114_update_ciphers/down.sql b/migrations/2018-08-27-172114_update_ciphers/down.sql diff --git a/migrations/2018-08-27-172114_update_ciphers/up.sql b/migrations/2018-08-27-172114_update_ciphers/up.sql @@ -0,0 +1,3 @@ +ALTER TABLE ciphers + ADD COLUMN + password_history TEXT; +\ No newline at end of file diff --git a/src/api/core/ciphers.rs b/src/api/core/ciphers.rs @@ -112,6 +112,8 @@ struct CipherData { Identity: Option<Value>, Favorite: Option<bool>, + + PasswordHistory: Option<Value>, } #[post("/ciphers/admin", data = "<data>")] @@ -177,6 +179,7 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head type_data["Name"] = Value::String(data.Name.clone()); type_data["Notes"] = data.Notes.clone().map(Value::String).unwrap_or(Value::Null); type_data["Fields"] = data.Fields.clone().unwrap_or(Value::Null); + type_data["PasswordHistory"] = data.PasswordHistory.clone().unwrap_or(Value::Null); // TODO: ******* Backwards compat end ********** cipher.favorite = data.Favorite.unwrap_or(false); @@ -184,6 +187,7 @@ fn update_cipher_from_data(cipher: &mut Cipher, data: CipherData, headers: &Head cipher.notes = data.Notes; cipher.fields = data.Fields.map(|f| f.to_string()); cipher.data = type_data.to_string(); + cipher.password_history = data.PasswordHistory.map(|f| f.to_string()); cipher.save(&conn); diff --git a/src/db/models/cipher.rs b/src/db/models/cipher.rs @@ -32,6 +32,7 @@ pub struct Cipher { pub data: String, pub favorite: bool, + pub password_history: Option<String>, } /// Local methods @@ -55,6 +56,7 @@ impl Cipher { fields: None, data: String::new(), + password_history: None, } } } @@ -77,6 +79,10 @@ impl Cipher { let fields_json: JsonValue = if let Some(ref fields) = self.fields { serde_json::from_str(fields).unwrap() } else { JsonValue::Null }; + + let password_history_json: JsonValue = if let Some(ref password_history) = self.password_history { + serde_json::from_str(password_history).unwrap() + } else { JsonValue::Null }; let mut data_json: JsonValue = serde_json::from_str(&self.data).unwrap(); @@ -108,6 +114,8 @@ impl Cipher { "Object": "cipher", "Edit": true, + + "PasswordHistory": password_history_json, }); let key = match self.type_ { diff --git a/src/db/schema.rs b/src/db/schema.rs @@ -21,6 +21,7 @@ table! { fields -> Nullable<Text>, data -> Text, favorite -> Bool, + password_history -> Nullable<Text>, } }