Ticket T967756
Visible to All Users

How to save a user's credentials in the 'XAF_Security_E4908/XPO/Xamarin.Forms' example

created 4 years ago (modified 4 years ago)

Hello,
I used the following example: XAF_Security_E4908/XPO/Xamarin.Forms/
I have the following requirements:

  • save a user's credentials when a user logs in for the first time.
  • when the user logs in the next time, reuse the saved credentials to log the user in (and skip the logon window).

Answers approved by DevExpress Support

created 4 years ago (modified 4 years ago)

save user's credentials when the user logs in for the first time

We don't offer any special mechanism to save/restore data in a Xamarin application, so you need to use common Xamarin techniques for this. You can refer to Xamarin support resources to find the most suitable way. I suggest starting with the following article: Xamarin.Essentials: Secure Storage - Xamarin | Microsoft Docs.

when the user logs in the next time, reuse the saved credentials to log the user in (and skip the logon window).

To accomplish this task, modify the App() method in the App.xaml.cs file so that it automatically logs in a user if there are stored credentials. You can see the code that logs in a user here: LoginViewModel.cs. Your modified code can look as follows:

C#
using DevExpress.Persistent.Base; using System; using Xamarin.Forms; using XamarinFormsDemo.Views; namespace XamarinFormsDemo { public partial class App : Application { public App() { //... var storedCredentials = GetStoredCredentials(); if(storedCredentials == default) { SetStartupPage(new LoginPage()); } else { XpoHelper.InitXpo(WebApiDataStoreClient.GetConnectionString("https://10.0.2.2:5001/xpo/"), storedCredentials.login, storedCredentials.pasword); SetStartupPage(new MainPage()); } } private void SetStartupPage(ContentPage contentPage) { if(Device.RuntimePlatform == Device.iOS) MainPage = contentPage; else MainPage = new NavigationPage(contentPage); } static (string login, string pasword) GetStoredCredentials() => throw new NotImplementedException("TODO");

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.