- Notifications
You must be signed in to change notification settings - Fork75
A small library to handle Android fingerprint API.
License
JesusM/FingerprintManager
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A small library to handle Android fingerprint APIs.
This library offers an easy way to handle authorisation and encryption tasks using AndroidFingerprint APIs. It's based on Android fingerprint dialog sample made by Google:https://github.com/googlesamples/android-FingerprintDialog.
This library can be used to provide basic authentication through fingerprint API, using manual password as backup option. It also allows you to encrypt messages using fingerprint APIs.This library provides a sample to show how it can be used.
You import via gradle fromhttps://jitpack.io adding this to your root build.gradle file:
allprojects { repositories {... maven { url'https://jitpack.io' } } }
and then adding the library as dependency:
dependencies { compile'com.github.JesusM:FingerprintManager:{latest_version}'}
(you can see which is the {latest_version} value fromreleases tab)
Create the fingerprint manager.
fingerPrintManager =KFingerprintManager(context,key);
key is the name for the symmetric key that is created in the Android Key Store. KFingerprintManager.InitialisationCallback contains a set of method that are called whether the fingerprint is ready to be used or when there is any error (like no fingerprint has been enrolled yet, or if there has been a problem initialising it).
Once the library is ready to be used, it provides two features: authentication and encryption.
Authentication provides the simplest way to authenticate a user. Once it uses its fingerprint scanner, you'll obtain enough information to allow any operation that requires a user authentication.The library API is pretty simple, just callstartAuthentication method passing to it a callback that will let you know the result of the operation. If the authentication went ok, you'll obtain aCryptoObject object that will let you use for authentication operations (seeencryption to see what you can do with that data)
Logic to authenticate using fingerprint:
fingerPrintManager.authenticate(object:KFingerprintManager.AuthenticationCallback {overridefunonAuthenticationFailedWithHelp(help:String?) {// Logic when decryption failed with a message }overridefunonAuthenticationSuccess() {// Logic when authentication has been successful }overridefunonSuccessWithManualPassword(password:String) {// Logic when authentication has been successful writting password manually }overridefunonFingerprintNotRecognized() {// Logic when fingerprint was not recognized }overridefunonFingerprintNotAvailable() {// Logic when fingerprint is not available }overridefunonCancelled() {// Logic when operation is cancelled by user } }, getSupportFragmentManager());
Encryption/decryption operations will be only done using fingerprint APIs, so if fingerprint is not present or suitable, it will fail.
Logic to encrypt an String message using the library:
fingerPrintManager.encrypt(messageToBeEncrypted,object:KFingerprintManager.EncryptionCallback {overridefunonFingerprintNotRecognized() {// Logic when fingerprint was not recognized }overridefunonAuthenticationFailedWithHelp(help:String?) {// Logic when decryption failed with a message }overridefunonFingerprintNotAvailable() {// Logic when fingerprint is not available }overridefunonEncryptionSuccess(messageEncrypted:String) {// Logic to handle the encrypted message }overridefunonEncryptionFailed() {// Logic to handle decryption failure }overridefunonCancelled() {// Logic when operation is cancelled by user } }, getSupportFragmentManager());
Logic to decrypt an already encrypted message:
fingerPrintManager.decrypt(messageToDecrypt,object:KFingerprintManager.DecryptionCallback {overridefunonDecryptionSuccess(messageDecrypted:String) {// Logic that handles successful decryption result }overridefunonDecryptionFailed() {// Logic to handle decryption failure }overridefunonFingerprintNotRecognized() {// Logic when fingerprint was not recognized }overridefunonAuthenticationFailedWithHelp(help:String?) {// Logic when decryption failed with a message }overridefunonFingerprintNotAvailable() {// Logic when fingerprint is not available }overridefunonCancelled() {// Logic when operation is cancelled by user } }, getSupportFragmentManager());
The library allows you to customise how the visual component is displayed. In order to do that, you can follow these steps:
1.- Declare a xml them like this:
<style name ="DialogThemeLight"parent="Theme.AppCompat.Light.Dialog.MinWidth"> <itemname="colorAccent">@color/dialog_light_theme_accent</item> <itemname="android:colorAccent">@color/dialog_light_theme_accent</item> <itemname="android:background">@color/dialog_light_theme_background</item> <itemname="android:textColorPrimary">@color/dialog_light_theme_text_color_primary</item> <itemname="android:textColorSecondary">@color/dialog_light_theme_text_color_secondary</item> </style>
2.- Once you have the theme, the library provides a method to set it:
fingerPrintManager.setAuthenticationStyle(theme);
In thescreenshots section you can see some samples of the customisations.
- Android Fingerprint Authentication:https://developer.android.com/about/versions/marshmallow/android-6.0.html#fingerprint-authentication
MIT License
Copyright 2016 The Android Open Source Project, Inc.
Copyright (c) 2017 Jesús
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
About
A small library to handle Android fingerprint API.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.



