简体   繁体   中英

iOS/Xamarin How can I use Biometrics to allow users to log in to accounts that already have usernames and passwords?

I am working with Xamarin on a Cross Platform application. There is an existing log in feature that takes in a username and password. I was tasked with adding a feature where users may log in using Touch ID or Face ID. I have read through the documentation on Local Authorization, as well as a slew of other tutorials, but I can't get over a major hurdle, which is how can I link Biometric information with user account information if Local Authorization has a system set in place which disallows said information from being stored anywhere other than the device's hardware.

void AuthenticateMe(object sender, EventArgs e)
        {
            var context = new LAContext();
            NSError AuthError;
            var myReason = new NSString("To Sign In to App");

            if (context.CanEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, out AuthError))
            {
                var replyHandler = new LAContextReplyHandler((success, error) =>
                {
                    Device.BeginInvokeOnMainThread(() =>
                    { 
                        if (success)
                    //If Bob123's fingerprint worked
                        {
                           //Goes to Bob123's home page 
                            SetCurrentMainPage();
                        }
                        else
                        { 
                            //Redirects to login page where Bob can login as Bob123
                            // Show fallback mechanism here
                        }
                    });
                });
                context.EvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, myReason, replyHandler);
            };
        }

Eg How can Bob123 login with both his fingerprint and his username?

When the user logs in with regular login, store the username and password in SecureStorage.

https://docs.microsoft.com/en-us/xamarin/essentials/secure-storage?tabs=ios

It is easy to store and access the user details. There's also a video in that link.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM