Biometric Authentication in your .NET MAUI Application

Cedric Gabrang
2 min readJul 18, 2022

--

Photo by Onur Binay on Unsplash

Biometrics on mobile devices give applications with an alternative to the conventional process of user authentication. With the unique identifiers of your biology and behaviors, this may seem foolproof.

Here’s how you can authenticate via fingerprint (Android) or Touch ID / Face ID (iOS) in your .NET MAUI application.

Requirements

A fingerprint or Touch ID must already be enrolled with the device for each user that is to be authenticated. This involves setting up a screen lock that uses a password, PIN, swipe pattern, or facial recognition.

Setup

In your .NET MAUI project, install Plugin.Fingerprint by Sven-Michael Stübe. You’ll need version 3.0.0-beta.1, which is currently in pre-release (as of this writing), so please check “Include prerelease”:

The Plugin.Fingerprint package in the NuGet Package Manager.

Android

The target SDK version has to be >= 6.0

Request the permission in AndroidManifest.xml

Set the resolver of the current Activity

Skip this, if you use the MvvMCross Plugin.

Add the resolver in your MainActivity like:

iOS

Add NSFaceIDUsageDescription to your Info.plist to describe the reason your app uses Face ID. Otherwise the App will crash when you start a Face ID authentication on iOS 11.3+.

<key>NSFaceIDUsageDescription</key>
<string>Need your face to unlock secrets!</string>

Usage

Add a button with a click handler. Inside the event handler in the code-behind, add the following code:

When you press the button, it will check the availability of fingerprint or facial recognition of the device. If available, it will then ask you to authenticate. See how it works on Android:

Fingerprint authentication on an Android device

You can also do the same with dependency injection in your ViewModel by using the IFingerprint interface and resolving it to CrossFingerprint.Current in your MauiProgram like:

You can also set the AllowAlternativeAuthentication to true if you want it to fall back to using a pin. Then the FallbackTitle like "Use Password" or “Use PIN”.

Well, that’s it on how to incorporate your device’s biometrics into your .NET MAUI app. Try it in your own, you can find all of the code example on my GitHub.

--

--

Cedric Gabrang
Cedric Gabrang

Written by Cedric Gabrang

Xamarin | .NET MAUI, C# Developer | React Native | Twitter: @cedric_gabrang

No responses yet