The idea is to allow the user to auto-login after his/her first verified connection. Here, you will find the simple project.
First of all, you need to install this NuGet Package. Or use this command in VS's Package Manager Console.
- Install-Package AutoLogin.Mabrouk -Version 1.1.2
Now, let's code.
In your App.xaml.cs (like here) class which represents the cross-platform mobile application, you write your test. If the user's information is already saved, then you get directly to the main page and the login page will be ignored,
- public App() {
- InitializeComponent();
-
- if (CrossAutoLogin.Current.UserIsSaved) MainPage = new AutoLoginSimple.HomePage();
- else MainPage = new AutoLoginSimple.MainPage();
- }
Then, in your connection's button event, save your user's info (Email, Password) like :
- private void Connect_clicked(object sender, EventArgs e)
- {
-
-
-
- if (CrossAutoLogin.Current.UserIsSaved == false)
- {
- CrossAutoLogin.Current.SaveUserInfos(entry_email.Text, entry_password.Text);
- }
-
- Navigation.PushModalAsync(new HomePage());
- }
Also, if you want to delete user's information, for exemple in DISCONNECT button, you can simply add this line of code -
CrossAutoLogin.Current.DeleteUserInfos();
Example
- private void Disconnect_clicked(object sender, EventArgs e)
- {
- CrossAutoLogin.Current.DeleteUserInfos();
- Navigation.PopModalAsync();
- }
Source code is available on GitHub.
I hope this tutorial was helpful for you.