{"id":330,"date":"2022-11-28T17:05:08","date_gmt":"2022-11-28T17:05:08","guid":{"rendered":"https:\/\/learnmobiledevelopment.com\/?p=330"},"modified":"2023-01-18T17:01:36","modified_gmt":"2023-01-18T17:01:36","slug":"biometric-authentication-in-xamarin-forms","status":"publish","type":"post","link":"https:\/\/learnmobiledevelopment.com\/index.php\/2022\/11\/28\/biometric-authentication-in-xamarin-forms\/","title":{"rendered":"Implementation Of Biometric Authentication in Xamarin Forms"},"content":{"rendered":"\n<p>Now a days most of the mobile applications that use biometric authentication to secure data access. This allows users to authenticate via the fingerprint sensor and the face ID on those devices that have these capabilities. In this article, I\u2019m going to show you how to add <strong>Biometric Authentication<\/strong> <strong>in Xamarin<\/strong> Forms application.<\/p>\n\n\n\n<p style=\"font-size:25px\"><strong>Let\u2019s Start<\/strong><\/p>\n\n\n\n<p>In this sample demo we will use <strong><a href=\"https:\/\/www.nuget.org\/packages\/Plugin.Fingerprint\/\" target=\"_blank\" rel=\"noopener\" title=\"\">Plugin.Fingerprint<\/a><\/strong> nuget package. <\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>Plugin.Fingerprint<\/strong><\/p>\n\n\n\n<p>Plugin.Fingerprint enables us to authenticate the user via fingerprint or face id or any other biometric.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>1 &#8211; Install<strong> Plugin.Fingerprint<\/strong> nuget<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget-1024x644.png\" alt=\"Xamarin Forms Biometric Authentication \" class=\"wp-image-332\" width=\"840\" height=\"528\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget-1024x644.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget-300x189.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget-768x483.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget-1536x967.png 1536w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget-850x535.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/11\/Fingerprint-Nuget.png 1802w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2 &#8211; iOS Setup<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>2.1 &#8211; Add &#8220;NSFaceIDUsageDescription&#8221; to your Info.plist to describe the reason your app uses Face ID<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;key>NSFaceIDUsageDescription&lt;\/key>\n&lt;string>Need your face to unlock secrets!&lt;\/string><\/pre>\n\n\n\n<p>thats it for iOS Let&#8217;s move to <strong>android<\/strong> <strong>setup<\/strong>.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3 &#8211; Android Setup<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>3.1 &#8211; Add &#8220;USE_FINGERPRINT&#8221; permission in manifest file<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;uses-permission android:name=\"android.permission.USE_FINGERPRINT\" \/><\/pre>\n\n\n\n<p>Set &#8220;<strong>Resolver<\/strong>&#8221; in &#8220;<strong>OnCreate()<\/strong>&#8221; method of <strong>MainActivity.cs<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">CrossFingerprint.SetCurrentActivityResolver(() => Xamarin.Essentials.Platform.CurrentActivity);<\/pre>\n\n\n\n<p>Now, Setup is completed for android as well.<\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>4 &#8211; Setting up the UI<\/strong><\/p>\n\n\n\n<p class=\"has-medium-font-size\"><strong>4.1 &#8211; Creating a MainPage.xaml<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"xml\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\"1.0\" encoding=\"utf-8\" ?>\n&lt;ContentPage\n    x:Class=\"XFBiometric.MainPage\"\n    xmlns=\"http:\/\/xamarin.com\/schemas\/2014\/forms\"\n    xmlns:x=\"http:\/\/schemas.microsoft.com\/winfx\/2009\/xaml\">\n\n    &lt;StackLayout>\n        &lt;Frame\n            Padding=\"24\"\n            BackgroundColor=\"#2196F3\"\n            CornerRadius=\"0\">\n            &lt;Label\n                Margin=\"0,20,0,0\"\n                FontSize=\"36\"\n                HorizontalTextAlignment=\"Center\"\n                Text=\"Biometric Sample\"\n                TextColor=\"White\" \/>\n        &lt;\/Frame>\n\n\n        &lt;StackLayout\n            x:Name=\"StackContainer\"\n            Margin=\"0,150,0,0\"\n            IsVisible=\"False\"\n            VerticalOptions=\"CenterAndExpand\">\n\n            &lt;Image\n                x:Name=\"ImgSuccess\"\n                HeightRequest=\"200\"\n                WidthRequest=\"200\" \/>\n\n            &lt;Label\n                x:Name=\"LblMsg\"\n                FontAttributes=\"Bold\"\n                FontSize=\"25\"\n                HorizontalTextAlignment=\"Center\"\n                TextColor=\"Gray\" \/>\n\n        &lt;\/StackLayout>\n\n        &lt;Button\n            x:Name=\"BtnAuthenticate\"\n            Margin=\"0,0,0,50\"\n            Padding=\"20,15\"\n            BackgroundColor=\"#2196F3\"\n            Clicked=\"OnAuthenticateClicked\"\n            CornerRadius=\"30\"\n            FontAttributes=\"Bold\"\n            FontSize=\"20\"\n            HorizontalOptions=\"Center\"\n            Text=\"Authenticate\"\n            TextColor=\"White\"\n            VerticalOptions=\"EndAndExpand\" \/>\n\n    &lt;\/StackLayout>\n&lt;\/ContentPage><\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>4.2 &#8211; MainPage.xaml.cs<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"csharp\" data-enlighter-theme=\"dracula\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">using System;\nusing System.Collections.Generic;\nusing System.ComponentModel;\nusing System.Linq;\nusing System.Text;\nusing System.Threading.Tasks;\nusing Plugin.Fingerprint;\nusing Plugin.Fingerprint.Abstractions;\nusing Xamarin.Forms;\n\nnamespace XFBiometric\n{\n    public partial class MainPage : ContentPage\n    {\n        public MainPage()\n        {\n            InitializeComponent();\n        }\n\n        async void OnAuthenticateClicked(System.Object sender, System.EventArgs e)\n        {\n            var availability = await CrossFingerprint.Current.IsAvailableAsync();\n\n            if (!availability)\n            {\n                StackContainer.IsVisible = false;\n                await DisplayAlert(\"Warning!\", \"No biometrics available\", \"OK\");\n\n                return;\n            }\n\n            var authResult = await CrossFingerprint.Current.AuthenticateAsync(new AuthenticationRequestConfiguration(\"Heads up!\", \"Please validate biometric !!\"));\n\n            if (authResult.Authenticated)\n            {\n                Device.BeginInvokeOnMainThread(() =>\n                {\n                    StackContainer.IsVisible = true;\n                    ImgSuccess.Source = ImageSource.FromFile(\"success.png\");\n                    LblMsg.Text = \"Authentication Successfully !!\";\n                });\n            }\n            else\n            {\n                Device.BeginInvokeOnMainThread(() =>\n                {\n                    StackContainer.IsVisible = true;\n                    ImgSuccess.Source = ImageSource.FromFile(\"cross.jpg\");\n                    LblMsg.Text = \"Authentication Failed !!\";\n                });\n            }\n        }\n    }\n}<\/pre>\n\n\n\n<p class=\"has-medium-font-size\"><strong>5 &#8211; Result <\/strong><\/p>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1636\" style=\"aspect-ratio: 1032 \/ 1636;\" width=\"1032\" controls muted src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2022\/12\/Biometric-authentication-in-Xamarin.mov\"><\/video><\/figure>\n\n\n\n<p>That\u2019s all for now!<\/p>\n\n\n\n<p>You can check the full source code <a href=\"https:\/\/github.com\/Alam-Ashraf\/XFBiometricDemo\" target=\"_blank\" rel=\"noopener\" title=\"\">here<\/a><strong>.<\/strong><\/p>\n\n\n\n<p>Happy Coding!<strong> \ud83d\ude00<\/strong><\/p>\n\n\n\n<div style=\"height:35px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p class=\"has-medium-font-size\"><strong>You may also like<\/strong><\/p>\n\n\n\n<div class=\"wp-block-group is-content-justification-space-between is-nowrap is-layout-flex wp-container-core-group-is-layout-0dfbf163 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2023\/01\/18\/item-reordering-to-collectionview\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/Item-reordering-to-CollectionView-1024x682.png\" alt=\"Item reordering to CollectionView\" class=\"wp-image-733\" width=\"512\" height=\"341\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/Item-reordering-to-CollectionView-1024x682.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/Item-reordering-to-CollectionView-300x200.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/Item-reordering-to-CollectionView-768x512.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/Item-reordering-to-CollectionView-850x566.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/Item-reordering-to-CollectionView.png 1384w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to apply item reordering to CollectionView GridItemsLayout in MAUI<\/p>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\">\n<div class=\"wp-block-group is-vertical is-content-justification-center is-layout-flex wp-container-core-group-is-layout-4b2eccd6 wp-block-group-is-layout-flex\"><div class=\"wp-block-image is-style-default\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/learnmobiledevelopment.com\/index.php\/2023\/01\/02\/mediaelement-in-xamarin-forms\/\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-1024x737.png\" alt=\"MediaElement in Xamarin Forms\" class=\"wp-image-631\" width=\"512\" height=\"369\" srcset=\"https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-1024x737.png 1024w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-300x216.png 300w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-768x553.png 768w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin-850x612.png 850w, https:\/\/learnmobiledevelopment.com\/wp-content\/uploads\/2023\/01\/MediaElementInXamarin.png 1256w\" sizes=\"auto, (max-width: 512px) 100vw, 512px\" \/><\/a><\/figure>\n<\/div>\n\n\n<p class=\"has-text-align-center\">How to use MediaElement in Xamarin Forms<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Now a days most of the mobile applications that use biometric authentication to secure data access. This allows users to authenticate via the fingerprint sensor and the face ID on those devices that have these capabilities. In this article, I\u2019m going to show you how to add Biometric Authentication in Xamarin Forms application. Let\u2019s Start&#8230;<\/p>\n","protected":false},"author":1,"featured_media":346,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[1],"tags":[11,13,12],"class_list":["post-330","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-xamarin","tag-biometric-authentication-in-xamarin-forms","tag-faceid-authentication-in-xamarin-forms","tag-fingerprint-authentication-in-xamarin-forms"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/330","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/comments?post=330"}],"version-history":[{"count":22,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/330\/revisions"}],"predecessor-version":[{"id":761,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/posts\/330\/revisions\/761"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media\/346"}],"wp:attachment":[{"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/media?parent=330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/categories?post=330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learnmobiledevelopment.com\/index.php\/wp-json\/wp\/v2\/tags?post=330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}