Xamarin.Forms Remember-me Login using Secure Storage

Here we are going to implement the Remember-me feature for Login using Secure Storage in Xamarin.Forms 5 cross platform mobile app.

Secure Storage is part of Xamarin.Essentials nuget which has been included Xamarin.Forms 5 projects by default. It is useful to store small information securely on the device in the form of key-value pairs.

Create a new Xamarin.Forms project using Flyout template option. It will create the following files and folders in the Solution. Open the LoginViewModel to start making changes .

In LogiViewModel.cs we need the following code:
  1. Properties for UserName, Password and IsRemember
  2. LoginCommand and LoadCommand. User credentials will be saved during login and retrieved during Load.
  3. Resolve LoginService to validate login.

So out final LoginViewModel.cs looks like this:


In LoginPage.xaml Entry controls for username and password are added. Also, a checkbox for the Remember me option. To convert Appearing event to a command, Xamarin.CommunityToolkit nuget is added.

Full source code is here : github

In App.xaml add code to navigate to LoginPage. Now run your application, once you check the Remember me checkbox, user credentials will be automatically populated from the next time:

Github repo: https://github.com/deveshs22/Xamarin.Forms-Demo