Android login and password "cache"

Asked

Viewed 3,067 times

4

Hello, how to login automatically?

ex: I made an application for android with login, password and webservice, when the user logs I send the information and return true or false. How do I store in the phone the user and password informed for the next accesses do not ask the same ?

  • 4

    Kebler, my suggestion is to use SharedPreferences. It already has a standard security, but you can even encrypt if necessary. But the ideal is to save a token not a password. Have a look at the questions in the tag: http://answall.com/questions/tagged/sharedpreferences

  • I am just in this part of my project, I am creating a token, for now I put together the login and encryption information, and saved using sharedpreferences. In my case I am doing SSL/TLS communication via socket , and every time the communication starts I send the token so the server can recognize the client.

  • If your communication is via http, I think every request you should send the token or else work with cookies can help, but I don’t know if it would be safe.

  • for your greater safety let the Sharedpreference private, [Activity.MODE_PRIVATE]

1 answer

5

You can user SharedPreferences to save the information, so the second time the user accesses your application you check if this information is filled and log in automatically.

Example to save information using SharedPreferences:

public static final String NOME_PREFERENCE = "INFORMACOES_LOGIN_AUTOMATICO";
SharedPreferences.Editor editor = getSharedPreferences(NOME_PREFERENCE, MODE_PRIVATE).edit();

 editor.putString("login", "usuario01");
 editor.putString("senha", "1234");
 editor.commit();

And for you to recover this saved information:

SharedPreferences prefs = getSharedPreferences(MY_PREFS_NAME, MODE_PRIVATE); 
String login= prefs.getString("login", null);
String senha= prefs.getString("senha", null);
if (login!= null) {
   // existe configuração salvar
} else {
  // não existe configuração salvar
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.