Forum Xamarin.Android

Easy Login App

JonasPTFLJonasPTFL Member ✭✭
edited March 2018 in Xamarin.Android

I want to make an Android-Login-App. First time you have to login with an username an password on the Login-Screen.
Then the App switches to Screen2.
And if I open the App another time. The App must stored the login.
So that I don't have to login again and go directly to Screen2.

But I'm not able to store the Login and go directly to Screen2...
So on my App, which I made, I have to login every time when I start the App.
I can't store the Login in a Database...
Can someone help me, how to store the data and to start directly the Screen2, when I open the App?

I would be very happy to receive an answer.
Thanks in advance. :)

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    edited March 2018
    Why can’t you store your data inside a db?
  • JonasPTFLJonasPTFL Member ✭✭
    Thank you for your answer ;)

    Im not so good with databases...
    So could you explain me how to store this type of data?
  • menontheChessboardmenontheChessboard TRMember ✭✭✭

    im new xamarin but i think you can use sqlite

    first create a class
    class LoginInfo
    {
    public string UserName{ get; set; }

            public string Password{ get; set; }
    
    
            public LoginInfo(string username, string password)
            {
                UserName= username;
                Password= password;
    
            }
    
            public LoginInfo()
            {
    
            }
    
            public override string ToString()
            {
                return UserName+ " " + Password;
            }
    }
    
    
    string dbPath = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "logininfo.db3");//path string for the sqlite database file. it must be global
    
    
    private void BtnLogin_Click(object sender, System.EventArgs e){
    
    var db = new SQLiteConnection(dbPath);//db connection
    
    db.CreateTable<LoginInfo>();
    
    LoginInfo myInfo = new LoginInfo (editUserName.Text, editPassword.Text);
    
     db.Insert(myInfo);
    
    
    }
    protected override async void OnCreate(Bundle savedInstanceState)
    
    var db = new SQLiteConnection(dbPath);
    
    
                        var table = db.Table<LoginInfo>();
    
    
                        foreach (var item in table){
    editUserName.Text=item.UserName;
    editPassword.Text=item.Password;
    }
    
  • JonasPTFLJonasPTFL Member ✭✭
    Thank you very much for your answers!
    I will test the code in my App and write again, wheter it is working.
  • JonasPTFLJonasPTFL Member ✭✭

    Sorry, but have somebody found an example Login Android App?
    Maybe a link to an GitHub project or something?!

Sign In or Register to comment.