mirror of
https://github.com/dani-garcia/vaultwarden.git
synced 2025-08-17 16:25:25 +00:00
Password History Support (#155)
This commit is contained in:
parent
3767de9cfe
commit
a92a42af72
6 changed files with 37 additions and 6 deletions
20
migrations/2018-08-27-172114_update_ciphers/down.sql
Normal file
20
migrations/2018-08-27-172114_update_ciphers/down.sql
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
ALTER TABLE ciphers RENAME TO oldCiphers;
|
||||||
|
|
||||||
|
CREATE TABLE ciphers (
|
||||||
|
uuid TEXT NOT NULL PRIMARY KEY,
|
||||||
|
created_at DATETIME NOT NULL,
|
||||||
|
updated_at DATETIME NOT NULL,
|
||||||
|
user_uuid TEXT REFERENCES users (uuid),
|
||||||
|
organization_uuid TEXT REFERENCES organizations (uuid),
|
||||||
|
type INTEGER NOT NULL,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
notes TEXT,
|
||||||
|
fields TEXT,
|
||||||
|
data TEXT NOT NULL,
|
||||||
|
favorite BOOLEAN NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
INSERT INTO ciphers (uuid, created_at, updated_at, user_uuid, organization_uuid, type, name, notes, fields, data, favorite)
|
||||||
|
SELECT uuid, created_at, updated_at, user_uuid, organization_uuid, type, name, notes, fields, data, favorite FROM oldCiphers;
|
||||||
|
|
||||||
|
DROP TABLE oldCiphers;
|
3
migrations/2018-08-27-172114_update_ciphers/up.sql
Normal file
3
migrations/2018-08-27-172114_update_ciphers/up.sql
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
ALTER TABLE ciphers
|
||||||
|
ADD COLUMN
|
||||||
|
password_history TEXT;
|
|
@ -168,9 +168,8 @@ struct EmailTokenData {
|
||||||
#[post("/accounts/email-token", data = "<data>")]
|
#[post("/accounts/email-token", data = "<data>")]
|
||||||
fn post_email_token(data: JsonUpcase<EmailTokenData>, headers: Headers, conn: DbConn) -> EmptyResult {
|
fn post_email_token(data: JsonUpcase<EmailTokenData>, headers: Headers, conn: DbConn) -> EmptyResult {
|
||||||
let data: EmailTokenData = data.into_inner().data;
|
let data: EmailTokenData = data.into_inner().data;
|
||||||
let mut user = headers.user;
|
|
||||||
|
|
||||||
if !user.check_valid_password(&data.MasterPasswordHash) {
|
if !headers.user.check_valid_password(&data.MasterPasswordHash) {
|
||||||
err!("Invalid password")
|
err!("Invalid password")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,10 +177,6 @@ fn post_email_token(data: JsonUpcase<EmailTokenData>, headers: Headers, conn: Db
|
||||||
err!("Email already in use");
|
err!("Email already in use");
|
||||||
}
|
}
|
||||||
|
|
||||||
user.email = data.NewEmail;
|
|
||||||
|
|
||||||
user.save(&conn);
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,6 +112,8 @@ struct CipherData {
|
||||||
Identity: Option<Value>,
|
Identity: Option<Value>,
|
||||||
|
|
||||||
Favorite: Option<bool>,
|
Favorite: Option<bool>,
|
||||||
|
|
||||||
|
PasswordHistory: Option<Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/ciphers/admin", data = "<data>")]
|
#[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["Name"] = Value::String(data.Name.clone());
|
||||||
type_data["Notes"] = data.Notes.clone().map(Value::String).unwrap_or(Value::Null);
|
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["Fields"] = data.Fields.clone().unwrap_or(Value::Null);
|
||||||
|
type_data["PasswordHistory"] = data.PasswordHistory.clone().unwrap_or(Value::Null);
|
||||||
// TODO: ******* Backwards compat end **********
|
// TODO: ******* Backwards compat end **********
|
||||||
|
|
||||||
cipher.favorite = data.Favorite.unwrap_or(false);
|
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.notes = data.Notes;
|
||||||
cipher.fields = data.Fields.map(|f| f.to_string());
|
cipher.fields = data.Fields.map(|f| f.to_string());
|
||||||
cipher.data = type_data.to_string();
|
cipher.data = type_data.to_string();
|
||||||
|
cipher.password_history = data.PasswordHistory.map(|f| f.to_string());
|
||||||
|
|
||||||
cipher.save(&conn);
|
cipher.save(&conn);
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ pub struct Cipher {
|
||||||
pub data: String,
|
pub data: String,
|
||||||
|
|
||||||
pub favorite: bool,
|
pub favorite: bool,
|
||||||
|
pub password_history: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Local methods
|
/// Local methods
|
||||||
|
@ -55,6 +56,7 @@ impl Cipher {
|
||||||
fields: None,
|
fields: None,
|
||||||
|
|
||||||
data: String::new(),
|
data: String::new(),
|
||||||
|
password_history: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -78,6 +80,10 @@ impl Cipher {
|
||||||
serde_json::from_str(fields).unwrap()
|
serde_json::from_str(fields).unwrap()
|
||||||
} else { JsonValue::Null };
|
} 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();
|
let mut data_json: JsonValue = serde_json::from_str(&self.data).unwrap();
|
||||||
|
|
||||||
// TODO: ******* Backwards compat start **********
|
// TODO: ******* Backwards compat start **********
|
||||||
|
@ -108,6 +114,8 @@ impl Cipher {
|
||||||
|
|
||||||
"Object": "cipher",
|
"Object": "cipher",
|
||||||
"Edit": true,
|
"Edit": true,
|
||||||
|
|
||||||
|
"PasswordHistory": password_history_json,
|
||||||
});
|
});
|
||||||
|
|
||||||
let key = match self.type_ {
|
let key = match self.type_ {
|
||||||
|
|
|
@ -21,6 +21,7 @@ table! {
|
||||||
fields -> Nullable<Text>,
|
fields -> Nullable<Text>,
|
||||||
data -> Text,
|
data -> Text,
|
||||||
favorite -> Bool,
|
favorite -> Bool,
|
||||||
|
password_history -> Nullable<Text>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue