diff --git a/src/KeePass.sln b/src/KeePass.sln index 85a88411..c531de97 100644 --- a/src/KeePass.sln +++ b/src/KeePass.sln @@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MasterKeePlugin", "MasterKe EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlayServicesTest", "PlayServicesTest\PlayServicesTest.csproj", "{B8E78075-3936-42E9-9AB4-C82B341935A6}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "App1", "App1\App1.csproj", "{A29ECF2C-3313-4F93-8B78-DC3F1319E835}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -378,6 +380,30 @@ Global {B8E78075-3936-42E9-9AB4-C82B341935A6}.ReleaseNoNet|Win32.Build.0 = Release|Any CPU {B8E78075-3936-42E9-9AB4-C82B341935A6}.ReleaseNoNet|x64.ActiveCfg = Release|Any CPU {B8E78075-3936-42E9-9AB4-C82B341935A6}.ReleaseNoNet|x64.Build.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Mixed Platforms.Deploy.0 = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|Win32.ActiveCfg = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Debug|x64.ActiveCfg = Debug|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Any CPU.Build.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Any CPU.Deploy.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Mixed Platforms.Deploy.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|Win32.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.Release|x64.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Any CPU.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Any CPU.Build.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Any CPU.Deploy.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Mixed Platforms.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Mixed Platforms.Build.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Mixed Platforms.Deploy.0 = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|Win32.ActiveCfg = Release|Any CPU + {A29ECF2C-3313-4F93-8B78-DC3F1319E835}.ReleaseNoNet|x64.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/keepass2android/PasswordActivity.cs b/src/keepass2android/PasswordActivity.cs index 824b0ef4..10121295 100644 --- a/src/keepass2android/PasswordActivity.cs +++ b/src/keepass2android/PasswordActivity.cs @@ -28,6 +28,7 @@ using Android.Graphics.Drawables; using Android.OS; using Android.Runtime; using Android.Views; +using Android.Views.InputMethods; using Android.Widget; using Java.Net; using Android.Preferences; @@ -638,6 +639,11 @@ namespace keepass2android _password = FindViewById(Resource.Id.password).Text; UpdateOkButtonState(); }; + FindViewById(Resource.Id.password).EditorAction += (sender, args) => + { + if ((args.ActionId == ImeAction.Done) || ((args.ActionId == ImeAction.ImeNull) && (args.Event.Action == KeyEventActions.Down))) + OnOk(); + }; FindViewById(Resource.Id.pass_otpsecret).TextChanged += (sender, args) => UpdateOkButtonState(); @@ -767,12 +773,17 @@ namespace keepass2android Button confirmButton = (Button) FindViewById(Resource.Id.pass_ok); confirmButton.Click += (sender, e) => { - App.Kp2a.GetFileStorage(_ioConnection) - .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), _ioConnection, - RequestCodePrepareDbFile, false); + OnOk(); }; } + private void OnOk() + { + App.Kp2a.GetFileStorage(_ioConnection) + .PrepareFileUsage(new FileStorageSetupInitiatorActivity(this, OnActivityResult, null), _ioConnection, + RequestCodePrepareDbFile, false); + } + private void InitializeTogglePasswordButton() { ImageButton btnTogglePassword = (ImageButton) FindViewById(Resource.Id.toggle_password); @@ -1277,7 +1288,13 @@ namespace keepass2android if (!_keepPasswordInOnResume) { - ClearEnteredPassword(); + if ( + PreferenceManager.GetDefaultSharedPreferences(this) + .GetBoolean(GetString(Resource.String.ClearPasswordOnLeave_key), true)) + { + ClearEnteredPassword(); + } + } _keepPasswordInOnResume = false; diff --git a/src/keepass2android/QuickUnlock.cs b/src/keepass2android/QuickUnlock.cs index 52df8697..af6c85e2 100644 --- a/src/keepass2android/QuickUnlock.cs +++ b/src/keepass2android/QuickUnlock.cs @@ -101,20 +101,7 @@ namespace keepass2android Button btnUnlock = (Button) FindViewById(Resource.Id.QuickUnlock_button); btnUnlock.Click += (object sender, EventArgs e) => { - KcpPassword kcpPassword = (KcpPassword) App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof (KcpPassword)); - String password = kcpPassword.Password.ReadString(); - String expectedPasswordPart = password.Substring(Math.Max(0, password.Length - quickUnlockLength), - Math.Min(password.Length, quickUnlockLength)); - if (pwd.Text == expectedPasswordPart) - { - App.Kp2a.UnlockDatabase(); - } - else - { - App.Kp2a.LockDatabase(false); - Toast.MakeText(this, GetString(Resource.String.QuickUnlock_fail), ToastLength.Long).Show(); - } - Finish(); + OnUnlock(quickUnlockLength, pwd); }; Button btnLock = (Button) FindViewById(Resource.Id.QuickUnlock_buttonLock); @@ -123,6 +110,11 @@ namespace keepass2android App.Kp2a.LockDatabase(false); Finish(); }; + pwd.EditorAction += (sender, args) => + { + if ((args.ActionId == ImeAction.Done) || ((args.ActionId == ImeAction.ImeNull) && (args.Event.Action == KeyEventActions.Down))) + OnUnlock(quickUnlockLength, pwd); + }; _intentReceiver = new QuickUnlockBroadcastReceiver(this); IntentFilter filter = new IntentFilter(); @@ -130,6 +122,24 @@ namespace keepass2android RegisterReceiver(_intentReceiver, filter); } + private void OnUnlock(int quickUnlockLength, EditText pwd) + { + KcpPassword kcpPassword = (KcpPassword) App.Kp2a.GetDb().KpDatabase.MasterKey.GetUserKey(typeof (KcpPassword)); + String password = kcpPassword.Password.ReadString(); + String expectedPasswordPart = password.Substring(Math.Max(0, password.Length - quickUnlockLength), + Math.Min(password.Length, quickUnlockLength)); + if (pwd.Text == expectedPasswordPart) + { + App.Kp2a.UnlockDatabase(); + } + else + { + App.Kp2a.LockDatabase(false); + Toast.MakeText(this, GetString(Resource.String.QuickUnlock_fail), ToastLength.Long).Show(); + } + Finish(); + } + private void OnLockDatabase() { CheckIfUnloaded(); diff --git a/src/keepass2android/Resources/values/config.xml b/src/keepass2android/Resources/values/config.xml index 34475db7..c88eda9a 100644 --- a/src/keepass2android/Resources/values/config.xml +++ b/src/keepass2android/Resources/values/config.xml @@ -172,4 +172,6 @@ PreloadDatabaseEnabled true + ClearPasswordOnLeave + \ No newline at end of file diff --git a/src/keepass2android/Resources/values/strings.xml b/src/keepass2android/Resources/values/strings.xml index b026a84f..9c1c8437 100644 --- a/src/keepass2android/Resources/values/strings.xml +++ b/src/keepass2android/Resources/values/strings.xml @@ -282,6 +282,9 @@ Use file transactions for writing databases Lock when screen off Lock the database when screen is switched off. + + Clear entered master password + Clear the entered master password when leaving the screen without unlocking the database. Lock when leaving app Lock the database when leaving the app by pressing the back button. diff --git a/src/keepass2android/Resources/xml/preferences.xml b/src/keepass2android/Resources/xml/preferences.xml index efe38dc4..fefe31e1 100644 --- a/src/keepass2android/Resources/xml/preferences.xml +++ b/src/keepass2android/Resources/xml/preferences.xml @@ -127,6 +127,15 @@ android:title="@string/show_kill_app" android:summary="@string/show_kill_app_summary" android:defaultValue="false"/> + + +