1 2 Android Confirm Credential Sample 3 =================================== 4 5 A sample that demonstrates how to use device credentials (PIN, Pattern, Password) in your app 6 7 Introduction 8 ------------ 9 10 This sample demonstrates how you can use device credentials (PIN, Pattern, Password) in your app 11 to authenticate the user before they are trying to complete some actions. 12 13 First you need to create a symmetric key in the Android Key Store using [KeyGenerator][1] 14 which can be only be used after the user has authenticated after the user is authenticated 15 with their device credentials and pass [KeyGenParameterSpec][2]. 16 17 By setting an integer value to the 18 [KeyGenParameterSpec.Builder.setUserAuthenticationValidityDurationSeconds][3], you can consider the 19 user as authenticated if the user has been authenticated with the device credentials 20 within the last x seconds. 21 22 Then by calling [KeyguardManager.createConfirmDeviceCredentialIntent][4], you can show a screen 23 to confirm device credentials to the user. 24 25 [1]: https://developer.android.com/reference/javax/crypto/KeyGenerator.html 26 [2]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.html 27 [3]: https://developer.android.com/reference/android/security/keystore/KeyGenParameterSpec.Builder.html#setUserAuthenticationValidityDurationSeconds%28int%29 28 [4]: https://developer.android.com/reference/android/app/KeyguardManager.html#createConfirmDeviceCredentialIntent%28java.lang.CharSequence,%20java.lang.CharSequence%29 29 30 Pre-requisites 31 -------------- 32 33 - Android SDK 23 34 - Android Build Tools v23.0.3 35 - Android Support Repository 36 37 Screenshots 38 ------------- 39 40 <img src="screenshots/1-purchase.png" height="400" alt="Screenshot"/> <img src="screenshots/2-show-confirm-credential.png" height="400" alt="Screenshot"/> <img src="screenshots/3-already-authenticated.png" height="400" alt="Screenshot"/> 41 42 Getting Started 43 --------------- 44 45 This sample uses the Gradle build system. To build this project, use the 46 "gradlew build" command or use "Import Project" in Android Studio. 47 48 Support 49 ------- 50 51 - Google+ Community: https://plus.google.com/communities/105153134372062985968 52 - Stack Overflow: http://stackoverflow.com/questions/tagged/android 53 54 If you've found an error in this sample, please file an issue: 55 https://github.com/googlesamples/android-Confirm Credential 56 57 Patches are encouraged, and may be submitted by forking this project and 58 submitting a pull request through GitHub. Please see CONTRIBUTING.md for more details. 59 60 License 61 ------- 62 63 Copyright 2016 The Android Open Source Project, Inc. 64 65 Licensed to the Apache Software Foundation (ASF) under one or more contributor 66 license agreements. See the NOTICE file distributed with this work for 67 additional information regarding copyright ownership. The ASF licenses this 68 file to you under the Apache License, Version 2.0 (the "License"); you may not 69 use this file except in compliance with the License. You may obtain a copy of 70 the License at 71 72 http://www.apache.org/licenses/LICENSE-2.0 73 74 Unless required by applicable law or agreed to in writing, software 75 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 76 WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 77 License for the specific language governing permissions and limitations under 78 the License. 79