Skip to content

Commit

Permalink
Ask for confirmation before deleting OTP settings from entries
Browse files Browse the repository at this point in the history
Closes #143
  • Loading branch information
Rookiestyle committed Jan 4, 2024
1 parent 68c738c commit 1a1a72c
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 7 deletions.
6 changes: 5 additions & 1 deletion Translations/KeePassOTP.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>23</TranslationVersion>
<TranslationVersion>24</TranslationVersion>
<item>
<key>OTPCopyTrayNoEntries</key>
<value>KPOTP - Keine Einträge vorhanden</value>
Expand Down Expand Up @@ -251,6 +251,10 @@ Die OTP-Datenbank wird dadurch NICHT gelöscht.
Klicke '{0}' um die OTP-Datenbank zu deaktivieren und zu löschen.
Klicke '{1}' um die OTP-Datenbank zu deaktivieren und nicht zu löschen.</value>
</item>
<item>
<key>ConfirmOTPDelete</key>
<value>Bitte bestätige das Löschen der OTP-Einstellungen.</value>
</item>
<item>
<key>OTPBackupDone</key>
<value>Das Entsperren der OTP-Datenbank ist fehlgeschlagen, die OTP-Datenbank wurde überschrieben.
Expand Down
4 changes: 4 additions & 0 deletions Translations/KeePassOTP.template.language.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ It will NOT delete the KeePassOTP database.
Click '{0}' to deactivate AND delete KeePassOTP database.
Click '{1}' to deactivate but not delete KeePassOTP database.</value>
</item>
<item>
<key>ConfirmOTPDelete</key>
<value>Please confirm deletion of OTP settings.</value>
</item>
<item>
<key>OTPBackupDone</key>
<value>Unlocking the existing OTP database failed and its content has been overwritten.
Expand Down
20 changes: 19 additions & 1 deletion src/KeePassOTPExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using KeePass.DataExchange;
using KeePass.Forms;
using KeePass.Plugins;
using KeePass.Resources;
using KeePass.UI;
using KeePass.Util;
using KeePass.Util.Spr;
Expand Down Expand Up @@ -307,6 +308,7 @@ private void OnOTPSetup(object sender, EventArgs e)
var otpSetup = new KeePassOTPSetup();
Tools.GlobalWindowManager(otpSetup);
otpSetup.OTP = OTPDAO.GetOTP(pe);
var psOldSeed = otpSetup.OTP.OTPSeed;

otpSetup.EntryUrl = pe.Strings.GetSafe(PwDefs.UrlField).ReadString();
otpSetup.InitEx(pe);
Expand All @@ -316,7 +318,17 @@ private void OnOTPSetup(object sender, EventArgs e)

if (otpSetup.ShowDialog(m_host.MainWindow) == DialogResult.OK)
{
OTPDAO.SaveOTP(otpSetup.OTP, pe);
bool bDoSave = true;
if (!psOldSeed.IsEmpty && otpSetup.OTP.OTPSeed.IsEmpty)
{
var dr = MessageBox.Show(PluginTranslate.ConfirmOTPDelete,
PluginTranslate.PluginName,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
bDoSave = dr == DialogResult.OK;
}
if (bDoSave) OTPDAO.SaveOTP(otpSetup.OTP, pe);
}
otpSetup.Dispose();
}
Expand Down Expand Up @@ -373,6 +385,12 @@ private void OnOTPQRCode(object sender, EventArgs e)

private void OnOTPDelete(object sender, EventArgs e)
{
var dr = MessageBox.Show(PluginTranslate.ConfirmOTPDelete,
PluginTranslate.PluginName,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2);
if (dr != DialogResult.OK) return;
foreach (var pe in m_host.MainWindow.GetSelectedEntries())
{
if (!OTPDAO.EnsureOTPUsagePossible(pe)) return;
Expand Down
4 changes: 4 additions & 0 deletions src/PluginTranslation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ It will NOT delete the KeePassOTP database.
Click '{0}' to deactivate AND delete KeePassOTP database.
Click '{1}' to deactivate but not delete KeePassOTP database.";
/// <summary>
/// Please confirm deletion of OTP settings.
/// </summary>
public static readonly string ConfirmOTPDelete = @"Please confirm deletion of OTP settings.";
/// <summary>
/// Unlocking the existing OTP database failed and its content has been overwritten.
/// A backup was saved as attachment in the following entry:
Expand Down
6 changes: 3 additions & 3 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("rookiestyle")]
[assembly: AssemblyProduct("KeePass Plugin")]
[assembly: AssemblyCopyright("Copyright 2021 - 2023")]
[assembly: AssemblyCopyright("Copyright 2021 - 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
Expand All @@ -30,5 +30,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.6.7")]
[assembly: AssemblyFileVersion("1.6.7")]
[assembly: AssemblyVersion("1.7")]
[assembly: AssemblyFileVersion("1.7")]
4 changes: 2 additions & 2 deletions version.info
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
:
KeePassOTP:1.6.7
KeePassOTP!de:23
KeePassOTP:1.7
KeePassOTP!de:24
KeePassOTP!fr:7
KeePassOTP!nl:3
KeePassOTP!pt:15
Expand Down

0 comments on commit 1a1a72c

Please sign in to comment.