diff --git a/CHANGELOG.md b/CHANGELOG.md index b4444774..76aaed2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ #### v0.2.6 * New feature: custom password preference with confirmation (Issue #26) + * New feature: use an individual password or PIN to lock the app (Issue #23) * New feature: support for Panic Trigger (PR #27 by carmebar) * Bug fix: OpenPGP with security token (Issue #20, PR #25 by carmebar) * Style/UI: add Contributors, Translators and Translate to About diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index b36b0602..f845f61c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,7 +19,6 @@ android:theme="@style/AppTheme.NoActionBar"> - @@ -27,6 +26,10 @@ android:name=".Activities.AboutActivity" android:parentActivityName=".Activities.MainActivity" android:theme="@style/AppTheme.NoActionBar" /> + = android.os.Build.VERSION_CODES.LOLLIPOP && km.isKeyguardSecure()) { - Intent authIntent = km.createConfirmDeviceCredentialIntent(getString(R.string.dialog_title_auth), getString(R.string.dialog_msg_auth)); - startActivityForResult(authIntent, INTENT_AUTHENTICATE); - } - - break; - - case "password": - Toast.makeText(this, "TODO: Password auth", Toast.LENGTH_LONG).show(); - - break; - - case "pin": - Toast.makeText(this, "TODO: PIN auth", Toast.LENGTH_LONG).show(); - - break; - - default: - break; + if (authMethod.equals("device")) { + KeyguardManager km = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP && km.isKeyguardSecure()) { + Intent authIntent = km.createConfirmDeviceCredentialIntent(getString(R.string.dialog_title_auth), getString(R.string.dialog_msg_auth)); + startActivityForResult(authIntent, INTENT_AUTHENTICATE); + } + } else if (authMethod.equals("password") || authMethod.equals("pin")) { + Intent authIntent = new Intent(this, AuthenticateActivity.class); + startActivityForResult(authIntent, INTENT_AUTHENTICATE); } - } // Initialize the main application @@ -357,8 +343,12 @@ public class MainActivity extends BaseActivity if (intent.getBooleanExtra("reload", false)) adapter.loadEntries(); } else if (requestCode == INTENT_AUTHENTICATE && resultCode != RESULT_OK) { + Toast.makeText(getBaseContext(), R.string.toast_auth_failed, Toast.LENGTH_LONG).show(); + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { finishAndRemoveTask(); + } else { + finish(); } } } diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java b/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java index c7f7aad0..a45eda9c 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Preferences/PasswordPreference.java @@ -98,18 +98,17 @@ public class PasswordPreference extends DialogPreference passwordInput.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); passwordConfirm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); - passwordInput.setTransformationMethod(new PasswordTransformationMethod()); - passwordConfirm.setTransformationMethod(new PasswordTransformationMethod()); } else if (mode == Mode.PIN) { passwordLayout.setHint(getContext().getString(R.string.settings_hint_pin)); passwordConfirm.setHint(R.string.settings_hint_pin_confirm); passwordInput.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); passwordConfirm.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD); - passwordInput.setTransformationMethod(new PasswordTransformationMethod()); - passwordConfirm.setTransformationMethod(new PasswordTransformationMethod()); } + passwordInput.setTransformationMethod(new PasswordTransformationMethod()); + passwordConfirm.setTransformationMethod(new PasswordTransformationMethod()); + passwordConfirm.addTextChangedListener(this); passwordInput.addTextChangedListener(this); diff --git a/app/src/main/res/layout/content_authenticate.xml b/app/src/main/res/layout/content_authenticate.xml new file mode 100644 index 00000000..7b69b2eb --- /dev/null +++ b/app/src/main/res/layout/content_authenticate.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 68127db3..6491f389 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,6 +4,8 @@ 16dp 24dp 32dp + 40dp + 16dp 0dp diff --git a/app/src/main/res/values/strings_auth.xml b/app/src/main/res/values/strings_auth.xml new file mode 100644 index 00000000..ded3911f --- /dev/null +++ b/app/src/main/res/values/strings_auth.xml @@ -0,0 +1,16 @@ + + + Authenticate + + + Password + PIN + + + Please enter your password to start andOTP. + Please enter your PIN to start andOTP. + + + Please set a password in the settings! + Please set a PIN in the settings! + \ No newline at end of file diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index 51ab443f..9534343f 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -38,6 +38,7 @@ Remove + Authentication failed, closing andOTP! Copied to clipboard Invalid QR Code @@ -48,7 +49,7 @@ Rename Security and Backups - Enter your device credentials to start andOTP. + Please enter your device credentials to start andOTP. Are you sure you want do remove this account? To keep your account information secure this app