Skip to content

Commit

Permalink
Don't color passwords when editing multiple entries
Browse files Browse the repository at this point in the history
When multiple entries are selected for simultaneous editing, and they have different passwords, KeePass indicates this by inserting the text "(Multiple values)" in the password field.
ColoredPassword will no longer color this text and keep the default color (grey) instead

Closes #19
  • Loading branch information
Rookiestyle committed Sep 23, 2022
1 parent fb28aad commit fb8c291
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
42 changes: 33 additions & 9 deletions src/ColoredSecureTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ protected override void OnParentChanged(EventArgs e)
Parent.PerformLayout();
}

//Don't show ColorTextBox if
// - m_form is set (KeyPromptForm or KeyCreationForm)
// AND
// - form.Shown event has not been raised yet
//
//This can result in a wrong CAPS LOCK warning tooltip - cf. https://github.com/Rookiestyle/ColoredPassword/issues/15
private bool m_bKeyFormShown = false;
//Don't show ColorTextBox if
// - m_form is set (KeyPromptForm or KeyCreationForm)
// AND
// - form.Shown event has not been raised yet
//
//This can result in a wrong CAPS LOCK warning tooltip - cf. https://github.com/Rookiestyle/ColoredPassword/issues/15
private bool m_bKeyFormShown = false;
private bool? m_bRememberedProtectionState = null;
public override void EnableProtection(bool bEnable)
{
Expand Down Expand Up @@ -304,7 +304,7 @@ protected override void Dispose(bool disposing)
}
}

private Form GetForm(Control c)
internal static Form GetForm(Control c)
{
if (c == null) return null;
var f = c.Parent;
Expand Down Expand Up @@ -383,11 +383,35 @@ public static List<CharRange> GetRanges(string s)
return lCR;
}

private bool? m_bIsPwEntryFormMultipleValues = null;
private bool IsPwEntryFormMultipleValues()
{
if (m_bIsPwEntryFormMultipleValues.HasValue) return m_bIsPwEntryFormMultipleValues.Value;
KeePass.Forms.PwEntryForm pef = ColoredSecureTextBox.GetForm(this) as KeePass.Forms.PwEntryForm;
if (pef == null)
{
m_bIsPwEntryFormMultipleValues = false;
return m_bIsPwEntryFormMultipleValues.Value;
}
m_bIsPwEntryFormMultipleValues = Tools.GetField("m_mvec", pef) != null;
if (m_bIsPwEntryFormMultipleValues.Value)
PluginDebug.AddInfo("PwEntryForm showing multiple entries: Do NOT color text (" + KeePass.Resources.KPRes.MultipleValues + ")", 0);
return m_bIsPwEntryFormMultipleValues.Value;
}

public void ColorText()
{
int nCursorPos = SelectionStart; //save cursor position
if (IsPwEntryFormMultipleValues() && this.Text == "(" + KeePass.Resources.KPRes.MultipleValues + ")")
{
//taken from KeePass.Util.MultipleValuesEx.ConfigureText
Color clrNormal = this.ForeColor;
Color clrMulti = UIUtil.ColorTowards(clrNormal, (UIUtil.IsDarkColor(
clrNormal) ? Color.White : Color.Black), 0.5);
this.ForeColor = clrMulti;
return;
}
SelectAll();

List<CharRange> lCR = GetRanges(this.Text);
List<string> lMsg = new List<string>();
bool bError = false;
Expand Down
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
// indem Sie "*" wie unten gezeigt eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.14.3")]
[assembly: AssemblyFileVersion("0.14.3")]
[assembly: AssemblyVersion("0.15")]
[assembly: AssemblyFileVersion("0.15")]
2 changes: 1 addition & 1 deletion version.info
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
:
ColoredPassword:0.14.3
ColoredPassword:0.15
ColoredPassword!de:6
ColoredPassword!pl:2
ColoredPassword!pt:2
Expand Down

0 comments on commit fb8c291

Please sign in to comment.