Biometric authentication and Android

Mauro Vacchio
Jan 25 · 2 min read

by Mauro Vacchio and Giampietro Fronteddu, Android Mobile Developers at OverApp.

For some time now, there has been an increasing need to find an alternative authentication system to Username / Password, in this sense biometric authentication systems are gaining more and more weight, and we at OverApp have had to integrate them.

Biometric authentication provides for the recognition of bodily characteristics, for some time Android devices have allowed recognition by fingerprint, in the most modern devices other more advanced recognition systems are being implemented: facial recognition or iris recognition.
Implementing a biometric authentication system is very easy: first we implement the correct dependencies on gradle

Then we create a Biometricable interface that contains the following methods:

To take advantage of a very convenient Kotlin feature, we create in the same file a biometricableHandler object that implements the Biometricable interface, and we implement all the methods in it, this allows us, by implementing the interface through this object, to have all the methods already implemented with the ability to override only those we need to change.

Now we create the Activity in which we will carry out the authentication process, to do this it will have to integrate, in addition to the AppCompatActivity, the interface that we have just created through the biometricableHandler object, inside this activity we insert a button that will start the process , to manage biometric authentication events in a personalized way we can override the onBiometricEvent () method.

This allows us to manage, obviously only locally, the biometric authentication, but what if I wanted to set a custom message if user wants to authenticate with iris or face recognition? How can I know if the device running the app is enabled to perform that type of recognition?

In this case, the SystemFeatures of the PackageManager intervene to help us: we add the canUseBiometricFeature method to our Biometricable that takes in the feature we want to use and implement it in this way in the biometricableHandler:

Then let’s add in the activity a method that lets us show a custom message according to the biometric authentication enabled in user’s device:

As we have seen, in this way, we easily managed to build an authentication system capable of using all the features of biometric authentication currently available, and on which it is possible to build a more comfortable and more user friendly authentication system than the classic username + password

by Mauro Vacchio and Giampietro Fronteddu, Android Mobile Developers at OverApp (https://www.overapp.com)

OverApp • Android

The OverApp Android Dev Magazine

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store