Skip to content

Commit 73306a1

Browse files
committed
Make the limitation that only advanced string fields starting with "KPH: " optional
1 parent 3a29380 commit 73306a1

6 files changed

Lines changed: 75 additions & 43 deletions

File tree

KeePassHttp.plgx

242 KB
Binary file not shown.

KeePassHttp/ConfigOpt.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ConfigOpt
1313
const string SearchInAllOpenedDatabasesKey = "KeePassHttp_SearchInAllOpenedDatabases";
1414
const string MatchSchemesKey = "KeePassHttp_MatchSchemes";
1515
const string ReturnStringFieldsKey = "KeePassHttp_ReturnStringFields";
16+
const string ReturnStringFieldsWithKphOnlyKey = "KeePassHttp_ReturnStringFieldsWithKphOnly";
1617
const string SortResultByUsernameKey = "KeePassHttp_SortResultByUsername";
1718
const string ListenerPortKey = "KeePassHttp_ListenerPort";
1819
const string ListenerHostKey = "KeePassHttp_ListenerHost";
@@ -70,6 +71,12 @@ public bool ReturnStringFields
7071
set { _config.SetBool(ReturnStringFieldsKey, value); }
7172
}
7273

74+
public bool ReturnStringFieldsWithKphOnly
75+
{
76+
get { return _config.GetBool(ReturnStringFieldsWithKphOnlyKey, true); }
77+
set { _config.SetBool(ReturnStringFieldsWithKphOnlyKey, value); }
78+
}
79+
7380
public bool SortResultByUsername
7481
{
7582
get { return _config.GetBool(SortResultByUsernameKey, true); }

KeePassHttp/Handlers.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,10 +470,17 @@ private ResponseEntry PrepareElementForResponseEntries(ConfigOpt configOpt, PwEn
470470
fields = new List<ResponseStringField>();
471471
foreach (var sf in entryDatabase.entry.Strings)
472472
{
473-
if (sf.Key.StartsWith("KPH: "))
473+
var sfValue = entryDatabase.entry.Strings.ReadSafe(sf.Key);
474+
if (configOpt.ReturnStringFieldsWithKphOnly)
474475
{
475-
var sfValue = entryDatabase.entry.Strings.ReadSafe(sf.Key);
476-
fields.Add(new ResponseStringField(sf.Key.Substring(5), sfValue));
476+
if (sf.Key.StartsWith("KPH: "))
477+
{
478+
fields.Add(new ResponseStringField(sf.Key.Substring(5), sfValue));
479+
}
480+
}
481+
else
482+
{
483+
fields.Add(new ResponseStringField(sf.Key, sfValue));
477484
}
478485
}
479486

KeePassHttp/OptionsForm.Designer.cs

Lines changed: 49 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

KeePassHttp/OptionsForm.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ private void OptionsForm_Load(object sender, EventArgs e)
4343
credSearchInAllOpenedDatabases.Checked = _config.SearchInAllOpenedDatabases;
4444
matchSchemesCheckbox.Checked = _config.MatchSchemes;
4545
returnStringFieldsCheckbox.Checked = _config.ReturnStringFields;
46+
returnStringFieldsWithKphOnlyCheckBox.Checked = _config.ReturnStringFieldsWithKphOnly;
4647
SortByUsernameRadioButton.Checked = _config.SortResultByUsername;
4748
SortByTitleRadioButton.Checked = !_config.SortResultByUsername;
4849
portNumber.Value = _config.ListenerPort;
4950
hostName.Text = _config.ListenerHost;
51+
52+
this.returnStringFieldsCheckbox_CheckedChanged(null, EventArgs.Empty);
5053
}
5154

5255
private void okButton_Click(object sender, EventArgs e)
@@ -59,6 +62,7 @@ private void okButton_Click(object sender, EventArgs e)
5962
_config.SearchInAllOpenedDatabases = credSearchInAllOpenedDatabases.Checked;
6063
_config.MatchSchemes = matchSchemesCheckbox.Checked;
6164
_config.ReturnStringFields = returnStringFieldsCheckbox.Checked;
65+
_config.ReturnStringFieldsWithKphOnly = returnStringFieldsWithKphOnlyCheckBox.Checked;
6266
_config.SortResultByUsername = SortByUsernameRadioButton.Checked;
6367
_config.ListenerPort = (int)portNumber.Value;
6468
_config.ListenerHost = hostName.Text;
@@ -212,5 +216,10 @@ private void SetRestartRequired()
212216
{
213217
_restartRequired = (_config.ListenerPort != portNumber.Value) || (_config.ListenerHost != hostName.Text);
214218
}
219+
220+
private void returnStringFieldsCheckbox_CheckedChanged(object sender, EventArgs e)
221+
{
222+
this.returnStringFieldsWithKphOnlyCheckBox.Enabled = this.returnStringFieldsCheckbox.Checked;
223+
}
215224
}
216225
}

KeePassHttp/OptionsForm.resx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,4 @@
117117
<resheader name="writer">
118118
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
119119
</resheader>
120-
<data name="label3.Text" xml:space="preserve">
121-
<value>If there are more fields needed than username + password,
122-
normal "String Fields" are used, which can be defined in the
123-
"Advanced" tab of an entry.
124-
String fields are returned in alphabetical order and have to start
125-
with "KPH: " (mind the space after KPH:).</value>
126-
</data>
127120
</root>

0 commit comments

Comments
 (0)