allow to create a special entry in the database with the QuickUnlock code as password, closes https://github.com/PhilippC/keepass2android/issues/331
This commit is contained in:
@@ -29,6 +29,7 @@ using Android.Preferences;
|
||||
using Android.Runtime;
|
||||
using Android.Support.Design.Widget;
|
||||
using Android.Views.InputMethods;
|
||||
using KeePassLib;
|
||||
using KeePassLib.Serialization;
|
||||
|
||||
namespace keepass2android
|
||||
@@ -107,7 +108,12 @@ namespace keepass2android
|
||||
|
||||
_quickUnlockLength = App.Kp2a.QuickUnlockKeyLength;
|
||||
|
||||
if (PreferenceManager.GetDefaultSharedPreferences(this)
|
||||
bool useUnlockKeyFromDatabase =
|
||||
QuickUnlockFromDatabaseEnabled
|
||||
&& FindQuickUnlockEntry() != null;
|
||||
|
||||
|
||||
if (useUnlockKeyFromDatabase || PreferenceManager.GetDefaultSharedPreferences(this)
|
||||
.GetBoolean(GetString(Resource.String.QuickUnlockHideLength_key), false))
|
||||
{
|
||||
txtLabel.Text = GetString(Resource.String.QuickUnlock_label_secure);
|
||||
@@ -157,6 +163,15 @@ namespace keepass2android
|
||||
|
||||
}
|
||||
|
||||
private bool QuickUnlockFromDatabaseEnabled =>
|
||||
PreferenceManager.GetDefaultSharedPreferences(this)
|
||||
.GetBoolean(GetString(Resource.String.QuickUnlockKeyFromDatabase_key), false);
|
||||
|
||||
private static PwEntry FindQuickUnlockEntry()
|
||||
{
|
||||
return App.Kp2a.GetDbForQuickUnlock()?.KpDatabase?.RootGroup?.Entries.SingleOrDefault(e => e.Strings.GetSafe(PwDefs.TitleField).ReadString() == "QuickUnlock");
|
||||
}
|
||||
|
||||
private const string NumFailedAttemptsKey = "FailedAttempts";
|
||||
|
||||
protected override void OnSaveInstanceState(Bundle outState)
|
||||
@@ -357,7 +372,17 @@ namespace keepass2android
|
||||
private string ExpectedPasswordPart
|
||||
{
|
||||
get
|
||||
{
|
||||
{
|
||||
if (QuickUnlockFromDatabaseEnabled)
|
||||
{
|
||||
var quickUnlockEntry = FindQuickUnlockEntry();
|
||||
if (quickUnlockEntry != null)
|
||||
{
|
||||
return quickUnlockEntry.Strings.ReadSafe(PwDefs.PasswordField).ToString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
KcpPassword kcpPassword = (KcpPassword) App.Kp2a.GetDbForQuickUnlock().KpDatabase.MasterKey.GetUserKey(typeof (KcpPassword));
|
||||
String password = kcpPassword.Password.ReadString();
|
||||
|
||||
|
@@ -35,6 +35,7 @@
|
||||
|
||||
<string name="app_name_debug">KP2ADbg</string>
|
||||
<string name="library_name"></string>
|
||||
<string name="QuickUnlockKeyFromDatabase_key">QuickUnlockKeyFromDatabase_key</string>
|
||||
<string name="default_file_path">/keepass/keepass.kdbx</string>
|
||||
<string name="donate_url"><![CDATA[https://philipp.crocoll.net/donate.php?lang=%1$s&app=%2$s]]></string>
|
||||
<string name="homepage">https://github.com/PhilippC/keepass2android</string>
|
||||
|
@@ -353,7 +353,10 @@
|
||||
<string name="QuickUnlockLength_summary">Maximum number of characters used as QuickUnlock password.</string>
|
||||
<string name="QuickUnlockHideLength_title">Hide QuickUnlock length</string>
|
||||
<string name="QuickUnlockHideLength_summary">If enabled, the length of the QuickUnlock code is not displayed on the QuickUnlock screen.</string>
|
||||
<string name="QuickUnlockKeyFromDatabase_title">QuickUnlock key from database entry</string>
|
||||
<string name="QuickUnlockKeyFromDatabase_summary">If the active database contains an entry with title QuickUnlock in its root group, the password of this entry is used as QuickUnlock code.</string>
|
||||
|
||||
|
||||
<string name="QuickUnlock_fail">QuickUnlock failed: incorrect password!</string>
|
||||
<string name="SaveAttachmentDialog_title">Save attachment</string>
|
||||
<string name="SaveAttachmentDialog_text">Please select where to save the attachment.</string>
|
||||
|
@@ -508,6 +508,14 @@
|
||||
android:defaultValue="false"
|
||||
android:title="@string/QuickUnlockHideLength_title"
|
||||
android:key="@string/QuickUnlockHideLength_key" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:enabled="true"
|
||||
android:persistent="true"
|
||||
android:summary="@string/QuickUnlockKeyFromDatabase_summary"
|
||||
android:defaultValue="false"
|
||||
android:title="@string/QuickUnlockKeyFromDatabase_title"
|
||||
android:key="@string/QuickUnlockKeyFromDatabase_key" />
|
||||
|
||||
</PreferenceScreen>
|
||||
<PreferenceScreen
|
||||
|
Reference in New Issue
Block a user