Skip to content

Commit

Permalink
Quick Unlock key can time out
Browse files Browse the repository at this point in the history
It is possible to define a general or database specific timeout for a Quick Unlock key.
If this timeout is reached, Quick Unlock is no longer possible.
  • Loading branch information
Rookiestyle committed Aug 28, 2021
1 parent 519929d commit 9474ba5
Show file tree
Hide file tree
Showing 12 changed files with 227 additions and 68 deletions.
10 changes: 9 additions & 1 deletion Translations/LockAssist.de.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Increment the TranslationVersion every time the translation file is updated
Also update the version.info file
-->
<TranslationVersion>1</TranslationVersion>
<TranslationVersion>2</TranslationVersion>
<item>
<key>FirstTimeInfo</key>
<value>Quick Unlock bietet verschiedene Konfigurationsmöglichkeiten.
Expand Down Expand Up @@ -108,4 +108,12 @@ Die Datenbank ist weiterhin gesperrt und kann nur mit dem vollständigen Hauptsc
<value>Quick Unlock bietet verschiedene Konfigurationsmöglichkeiten.
Bitte wähle eine der Möglichkeiten aus.</value>
</item>
<item>
<key>Hours</key>
<value>Stunden</value>
</item>
<item>
<key>Minutes</key>
<value>Minuten</value>
</item>
</Translation>
8 changes: 8 additions & 0 deletions Translations/LockAssist.template.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,12 @@ Please don't forget to activate this setting.</value>

The database stays locked and can only be unlocked with the original masterkey</value>
</item>
<item>
<key>Hours</key>
<value>Hours</value>
</item>
<item>
<key>Minutes</key>
<value>Minutes</value>
</item>
</Translation>
Binary file modified images/LockAssist - options.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/LockAssist.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private void OptionsFormShown(object sender, Tools.OptionsFormsEventArgs e)
{
PluginDebug.AddInfo("Show options", 0);
OptionsForm options = new OptionsForm();
options.InitEx(LockAssistConfig.GetOptions(m_host.Database));
options.InitEx(LockAssistConfig.GetQuickUnlockOptions(m_host.Database));
Tools.AddPluginToOptionsForm(this, options);
}

Expand All @@ -71,8 +71,8 @@ private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e)
bool shown = false;
OptionsForm options = (OptionsForm)Tools.GetPluginFromOptions(this, out shown);
if (!shown) return;
var MyOptions = LockAssistConfig.GetOptions(m_host.Database);
LockAssistConfig NewOptions = options.GetOptions();
var MyOptions = LockAssistConfig.GetQuickUnlockOptions(m_host.Database);
LockAssistConfig NewOptions = options.GetQuickUnlockOptions();
bool changedConfig = MyOptions.ConfigChanged(NewOptions, false);
bool changedConfigTotal = MyOptions.ConfigChanged(NewOptions, true);
PluginDebug.AddInfo("Options form closed", 0, "Config changed: " + changedConfig.ToString(), "Config total changed:" + changedConfigTotal.ToString());
Expand Down
11 changes: 10 additions & 1 deletion src/LockAssistConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace LockAssist
internal class LockAssistConfig
{
public static KeePass.App.Configuration.AceCustomConfig _config = KeePass.Program.Config.CustomConfig;
public static LockAssistConfig GetOptions(PwDatabase db)
public static LockAssistConfig GetQuickUnlockOptions(PwDatabase db)
{
LockAssistConfig conf = new LockAssistConfig();
conf.GetOptionsInternal(db);
Expand All @@ -25,13 +25,15 @@ private void GetOptionsInternal(PwDatabase db)
QU_UsePassword = db.CustomData.Get(LockAssistUsePassword) == "true";
if (!int.TryParse(db.CustomData.Get(LockAssistKeyLength), out QU_PINLength)) QU_PINLength = 4;
QU_UsePasswordFromEnd = db.CustomData.Get(LockAssistKeyFromEnd) == "false";
if (!int.TryParse(db.CustomData.Get(LockAssistQU_ValiditySeconds), out QU_ValiditySeconds)) QU_ValiditySeconds = 0;
}
else
{
QU_Active = _config.GetBool(LockAssistActive, false);
QU_UsePassword = _config.GetBool(LockAssistUsePassword, true);
QU_PINLength = (int)_config.GetLong(LockAssistKeyLength, 4);
QU_UsePasswordFromEnd = _config.GetBool(LockAssistKeyFromEnd, true);
QU_ValiditySeconds = (int)_config.GetLong(LockAssistQU_ValiditySeconds, 0);
}
}

Expand All @@ -46,6 +48,7 @@ public static bool FirstTime
public bool QU_UsePassword = true;
public bool QU_UsePasswordFromEnd = true;
public int QU_PINLength = 4;
public int QU_ValiditySeconds = 0;

public bool ConfigChanged(LockAssistConfig comp, bool CheckDBSpecific)
{
Expand All @@ -54,6 +57,7 @@ public bool ConfigChanged(LockAssistConfig comp, bool CheckDBSpecific)
if (QU_UsePassword != comp.QU_UsePassword) return true;
if (QU_PINLength != comp.QU_PINLength) return true;
if (QU_UsePasswordFromEnd != comp.QU_UsePasswordFromEnd) return true;
if (QU_ValiditySeconds != comp.QU_ValiditySeconds) return true;
return false;
}

Expand All @@ -65,6 +69,7 @@ public bool CopyFrom(LockAssistConfig NewOptions)
QU_UsePassword = NewOptions.QU_UsePassword;
QU_PINLength = NewOptions.QU_PINLength;
QU_UsePasswordFromEnd = NewOptions.QU_UsePasswordFromEnd;
QU_ValiditySeconds = NewOptions.QU_ValiditySeconds;
return SwitchToNoDBSpecific;
}

Expand All @@ -84,6 +89,7 @@ public void WriteConfig(PwDatabase db)
db.CustomData.Set(LockAssistKeyLength, QU_PINLength.ToString());
db.CustomData.Set(LockAssistKeyFromEnd, QU_UsePasswordFromEnd ? "true" : "false");
db.CustomData.Set(LockAssistQuickUnlockDBSpecific, "true");
db.CustomData.Set(LockAssistQU_ValiditySeconds, QU_ValiditySeconds.ToString());
FlagDBChanged(db);
}
else
Expand All @@ -92,6 +98,7 @@ public void WriteConfig(PwDatabase db)
_config.SetBool(LockAssistUsePassword, QU_UsePassword);
_config.SetLong(LockAssistKeyLength, QU_PINLength);
_config.SetBool(LockAssistKeyFromEnd, QU_UsePasswordFromEnd);
_config.SetLong(LockAssistQU_ValiditySeconds, QU_ValiditySeconds);
DeleteDBConfig(db);
}
}
Expand All @@ -111,6 +118,7 @@ public void DeleteDBConfig(PwDatabase db)
deleted |= db.CustomData.Remove(LockAssistKeyLength);
deleted |= db.CustomData.Remove(LockAssistKeyFromEnd);
deleted |= db.CustomData.Remove(LockAssistQuickUnlockDBSpecific);
deleted |= db.CustomData.Remove(LockAssistQU_ValiditySeconds);
if (deleted)
{
FlagDBChanged(db);
Expand All @@ -122,6 +130,7 @@ public void DeleteDBConfig(PwDatabase db)
private const string LockAssistUsePassword = "LockAssist.UsePassword";
private const string LockAssistKeyLength = "LockAssist.KeyLength";
private const string LockAssistKeyFromEnd = "LockAssist.KeyFromEnd";
private const string LockAssistQU_ValiditySeconds = "LockAssist.QU_validitySeconds";
private const string LockAssistFirstTime = "LockAssist.FirstTime";
private const string LockAssistQuickUnlockDBSpecific = "LockAssist.QuickUnlockDBSpecific";
}
Expand Down
102 changes: 73 additions & 29 deletions src/OptionsForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9474ba5

Please sign in to comment.