How to create a login screen

I am working on an application and want the user to enter their password in order to go to the main application screen. I need to know how I can save their password in xml or db when they first set their password, and how I can check if it enters the password correctly at login. Any help I can get would be greatly appreciated. Thanks.

+4
source share
4 answers

The problem with any of these solutions is what happens if the user forgets his password, which you can remove and reinstall, but then you will lose all the data for this application that was saved in the application folder. To get this, you must use the AccountManager .

There is an AcconutManger example in the sync example, although you need a method to verify your credentials. Be careful, this is not a simple example.

If you are happy that losing information is not a problem, you can simply save it to SharedPreferences, as suggested by other users.

You should also look at all the samples presented in the android sdk folder.

+3
source

You can use something called sharedPreference, but you may need to encrypt the password and save it.

Check using the general settings,

http://developer.android.com/guide/topics/data/data-storage.html

+1
source

You can do this with saving and retrieving data using the SQLite database in android, I recommend you read this tutorial: NotePad tutorial with a database , this is a very good tutorial.

+1
source

Use the SharedPreferences concept to store the password, and when starting the application, check it.

First save your data in the settings.

public void setSharedPreferences() { try { SharedPreferences sharedPreferences=getApplicationContext().getSharedPreferences("UserData", Context.MODE_PRIVATE); SharedPreferences.Editor editor=sharedPreferences.edit(); editor.putString("FirstName", StringUtils.capitalize(stringFirstName).trim()); editor.putString("LastName", StringUtils.capitalize(stringLastName).trim()); editor.putString("Email", stringEmail.toLowerCase().trim()); editor.putString("Password", stringPassword.trim()); editor.commit(); } catch (Exception e) { } } 

Check it at the entrance to the application.

 public boolean validateLogin(String email,String password) { try { SharedPreferences sharedPreferences=getApplicationContext().getSharedPreferences("UserData",Context.MODE_PRIVATE); if(email.toLowerCase().trim().equals(sharedPreferences.getString("Email",null)) && password.trim().equals(sharedPreferences.getString("Password",null))) { return true; } else { return false; } } catch (Exception e) { return false; } } 
+1
source

All Articles