Using a fingerprint in an app .Net Maui

Влад Тигинян 40 Reputation points
2023-06-07T06:19:54.2366667+00:00

Hi all.

I want to use fingerprint in my application (Plugin.Fingerprint by Sven-Michael Stübe).

I found several use cases:

https://cedricgabrang.medium.com/biometric-authentication-in-your-net-maui-application-dc35ec0c1f92

https://www.andreasnesheim.no/how-to-use-biometric-authentication-in-net-maui/

But I want the biometric verification to be carried out not on pressing the button, but when the application starts, after the splash screen.

Developer technologies | .NET | .NET MAUI
Developer technologies | .NET | Other
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. osjaetor 480 Reputation points
    2023-06-08T08:19:26.19+00:00

    Hi ,

    Here I suggest a snippet that could solve your problem:

    using Plugin.Fingerprint;
    using Plugin.Fingerprint.Abstractions;
    using Xamarin.Forms;
    
    public partial class App : Application
    {
        public App()
        {
            InitializeComponent();
        }
    
        protected override async void OnStart()
        {
            await Task.Delay(2000);
    
            var isBiometricAvailable = await CrossFingerprint.Current.IsAvailableAsync();
    
            if (isBiometricAvailable)
            {
                var authResult = await CrossFingerprint.Current.AuthenticateAsync("Biometric authentication required");
    
                if (authResult.Authenticated)
                {
                    MainPage = new MainPage();
                }
                else
                {
                    MainPage = new OtherAuthenticationPage();
                }
            }
            else
            {
                MainPage = new OtherAuthenticationPage();
            }
        }
    }
    

    Regards,

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.