Biometric Authentication: Steps to Implement in Android

Tags: security, privacy, android, beginners
Published: 2019-09-05 11:53:13

This article explores the use of google Biometric features to implement biometric authentication in a system. Using an API feature ‘BiometricPrompt’. Biometric Prompt allows building a biometric authentication process in Android. <a href="https://developer.android.com/reference/android/hardware/biometrics/BiometricPrompt">Biometric Prompt</a> class manages a system-provided dialog

Biometric fingerprint authentication is supported a long time ago by Android 6.0. This new biometric technology is more promising in the sense if authenticating the end-users with more accurate results. <a href="https://shuftipro.com/api/docs/?python#verification-services">Online identity verification APIs</a> use biometric technology to identify and verify the end-users, due to the growing roots of biometrics in the era of remote verification. A consistent level of <a href="https://shuftipro.com/blogs/biometric-authentication-its-applications-and-associated-constraints/">security</a> is adopted in the shape of biometrics whose need has made it compatible to fit in a large number of devices. 

<h3><b>#1 . Add permissions</b></h3> 

In the AndroidManifest.xml, add permissions to use biometric and specifically the fingerprint permission.

manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.an.biometric"

uses-permission android:name = “android.permission.USE_BIOMETRIC” 
uses-permission android:name = “android.permission.USE_FINGERPRINT” 



<b><h3> #2 . Check the device Compatibility</b></h3> 

Make sure that the device is compatible with biometric technology. Make sure that it has 6.0 or greater than 6.0 version, also holds a fingerprint sensor. User permission is needed to grant access to the fingerprint sensor and at least one fingerprint is registered to the device.

/* Check the android version
*Fingerprint supporting device check
*If minSdkversion is >= 23, then there is no need to apply the below check
*/

Public class Bio_utils{

Public static boolean  isBioPromptEnabled(){
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P);
}

/*Check fingerprint sensor check*/

Public static boolean  sdkversioncheck(){
return (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M);
}

/* Similarly embed checks of hardware support, fingerprint availability in device, and permission grant check*/
}


<b><h3>#3 . Biometric Prompt Dialog</b></h3> 

A biometric prompt dialog is only displayed in Android P. After ensuring the above checks, use Biometric Prompt builder to:

<b>setTitle():</b> set display title
<b>setSubtitle():</b> set the display subtitle
<b>setDescription():</b> set the description of dialog
<b>setNegativeButton():</b> set text for negative button 

Among the above list, setTitle() and setNegativeButton are required fields and others are optional.

<b><h3> #4 . BiometricPrompt.AuthenticationCallback</b></h3> 

To listen to the authentication events after certain functionality, user needs to respond to such events. On the basis of that response, BiometricPrompt.AuthenticationCallback is used.  Below are the four methods:

<b>OnAuthenticationSucceeded:</b> when the fingerprint successfully matches the ones that are registered
<b>OnAuthenticationFailed:</b> when the fingerprint does not match the ones that are registered in the device, at that time this callback prompts
<b>OnAuthenticationError:</b> when an error has occurred which is hard to handle and has encountered the completion of the authentication process
<b>OnAuthenticationHelp:</b> This method is used when a non-fatal error does occur during the authentication process


<b><h3>#5 . Create a UI Code</b></h3> 
Create UI code that seems similar to the dialog of Biometric Prompt.  Set the title, subtitle, update status, set description and insert Button. Proceed with the basic UI and enter detailed fanciness later. 
These above steps are the basics of implementing a biometric authentication system in Android.