Biometric authentication and Android
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:
- configureBiometrics(): where we actually configure our Biometricable.
- showBiometricDialog(): in which we build the dialog in which the biometric check will be done
- canUseBiometrics(): which returns true if device supports biometrics.
- onBiometricEvent(): which reacts to the result of biometric authentication.
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)