Fingerprint Authentication in Xamarin Forms Mobile App


Listening is fun too.

Straighten your back and cherish with coffee - PLAY !

 
 

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 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).

Limitations

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.

Permission

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.


Step: 1

Open Visual Studio and select Xamarin project.

Trigger-in-Xamarin

Image: Create a Xamarin project



After selecting Xamarin forms, select Blank App for Android and iOS platforms.

Trigger-in-Xamarin

Image: Select template and platform.


Step: 2

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.


Step: 3

When we work on bio-metric we need to give permission for Android and iOS.

Open AndroidManifest.xml and add the below permission.


<uses-permission android:name="android.permission.USE_FINGERPRINT" />


Step: 4

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();
    }
}

One Stop Solution for Xamarin Mobile App Development ?

Your Search ends here.



Step: 5

Now, open the Android project and create a class.

FPService.cs


Step: 6

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");
        }
    }
}

Conclusion

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.

Fingerprint Authentication in Xamarin Forms Mobile App

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 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).

Limitations

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.

Permission

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.


Step: 1

Open Visual Studio and select Xamarin project.

Trigger-in-Xamarin

Image: Create a Xamarin project



After selecting Xamarin forms, select Blank App for Android and iOS platforms.

Trigger-in-Xamarin

Image: Select template and platform.


Step: 2

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.


Step: 3

When we work on bio-metric we need to give permission for Android and iOS.

Open AndroidManifest.xml and add the below permission.


<uses-permission android:name="android.permission.USE_FINGERPRINT" />


Step: 4

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();
    }
}

One Stop Solution for Xamarin Mobile App Development ?

Your Search ends here.



Step: 5

Now, open the Android project and create a class.

FPService.cs


Step: 6

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");
        }
    }
}

Conclusion

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.

  • Pin It
TOP