Nowadays, almost all applications provide fingerprint or face id or any other biometric system for secure data access. Fingerprint and face id are the most secure way to use application and secure the user data. In Xamarin, using the native code this biometric process should be done for each platform.
Xamarin forms forms allows you to share a single code on multiple platforms and you can also share application UI on all platforms. Xamarin forms have their own filesystem. Using Xamarin forms we can authenticate a user’s fingerprint, face id, and any other biometric authentication. There are some plugins are available for making easy this biometric authentication cross-platform.
For this authentication, we required a version of Visual Studio 2017 or later (Windows or Mac).
In Xamarin Forms, there is a limitation for fingerprint and face id, it will not store in your application database for security reasons. It will be store in your mobile hardware and that is the OS level data. Not all android devices are supported face id detection some android devices support this feature.
For using the face id or fingerprint or other bios metric so firstly we need to add permissions for both Android and iOS.
Now, let’s start with the implementation.
Open Visual Studio and select Xamarin project.
Image: Create a Xamarin project
After selecting Xamarin forms, select Blank App for Android and iOS platforms.
Image: Select template and platform.
When we started a project first we need to add the NuGet package, for adding package Go to Tools -> NuGet Package Manager -> Manage NuGet Packages for a solution and add Plugin.Fingerprint Package.
When we work on bio-metric we need to give permission for Android and iOS.
Open AndroidManifest.xml and add the below permission.
Now, create a file in a shared project.
FingerPrintService.cs
using System; using System.Threading.Tasks; namespace FingerprintExample { public interface FingerPrintService { String GetType(); Task UserID(); bool fingerprintEnabled(); } }
Now, open the Android project and create a class.
FPService.cs
After that, we create a fingerprint handler to handle the fingerprint callback.
FingerPrintHandler.cs
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Support.V4.Hardware.Fingerprint; using Android.Views; using Android.Widget; using Xamarin.Forms; namespace FingerprintExample.Droid { public class FingerPrintHandler : FingerprintManagerCompat.AuthenticationCallback { private Context mainActivity; public bool AuthResult; public FingerPrintHandler(Context mainActivity) { this.mainActivity = mainActivity; } internal void Startprog(FingerprintManagerCompat fingerprintManager, FingerprintManagerCompat.CryptoObject cryptoObject) { CancellationSignal cancellationSignal = new CancellationSignal(); } public override void OnAuthenticationFailed() { FPService.IsAutSucess = false; Toast.MakeText(mainActivity, "Fingerprint Authentication failed!", ToastLength.Long).Show(); MessagingCenter.Send("Auth", "Fail"); } public override void OnAuthenticationSucceeded(FingerprintManagerCompat.AuthenticationResult result) { FPService.IsAutSucess = true; Toast.MakeText(mainActivity, "Fingerprint Authentication Success", ToastLength.Long).Show(); MessagingCenter.Send("Auth", "Success"); } } }
In this blog, we can see how to add fingerprint authentication to our app. Most of the users are uses a fingerprint sensor instead of entering a password because is easier than typing a password. And it carries a more security key it’s not easy to access fingerprint sensor to other users. Most advantages of fingerprint sensor are you cannot forget a fingerprint and in password, you can create a strong password but there is a chance that the user has to guess a password and, in a fingerprint, no one can guess a fingerprint.
December 17, 2024
July 29, 2021
July 22, 2021
July 20, 2021
Well do everything we can to make our next best project!
Check out our most recent blogs
December 17, 2024
Excel remains one of the handy tools for professionals to handle data and perform data analysis to gain valuable insights. However, it does lack functionality to perform complex tasks...
July 29, 2021
What is Angular? Angular is a frontend development framework used for building single-page client applications using HTML and Typescript. It is written in Typescript. What...
July 22, 2021
What is a Compiler? A compiler is nothing but a part of code that converts one programming language to another. If we talk about some simple programming languages like C, C++,...
Well do everything we can to make our next best project!