16

How to use biometric authentication in .NET MAUI

 2 years ago
source link: https://www.andreasnesheim.no/how-to-use-biometric-authentication-in-net-maui/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Biometric authentication has become an increasingly integral part of mobile apps to ensure that the user is the rightful owner of the device that they’re using. Here’s how you can authenticate via Face ID (iOS) or fingerprint (Android / iOS) in your .NET MAUI app.

Add the package

In your .NET MAUI project, install the Plugin.Fingerprint NuGet package. You’ll need version 3.0.0-beta.1, which is currently in pre-release, so remember to check “Include prerelease”:

The Plugin.Fingerprint package in the NuGet Package Manager.

Follow the guide on GitHub for how to set it up for your .NET MAUI project. The guide is currently located under the maui-support branch, so if the link doesn’t work it’s already been merged in and you can use the previously provided link.

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

Now when you click the button, you will be asked to authenticate yourself via facial recognition or fingerprint. Check the video below to see how it works on Android:

Fingerprint authentication on an Android emulator.

You can also do the same with dependency injection by using the IFingerprint interface and resolving it to CrossFingerprint.Current. See my GitHub code example for a full sample on how to do this. Note that this may not be best practice when it comes to using DI – I am only using this to provide a simple sample on how you could do this yourself.

Thoughts

I am always blown away at the community around Xamarin/.NET MAUI and how much work is put in by individuals who want to help out. If you found the package provided here useful, be sure to check the repository for the package and give it a star. As the package is still in beta for MAUI, make sure to provide feedback if you notice something.

As always, I’ve provided a code example on my GitHub that you can check out if you’d like. This sample was also featured on the .NET MAUI Community Standup for May 2022.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK