开发者

how to save login details of android app?

I have a android application which needs username and password to login. I need to save the username and password locally in phone or somewhere to use them when the user opens the app next time and logins to the app automatically without showing the login screen

    EditText input1 = (EditText) findViewById(R.id.usertext);
    EditText input2 = (Ed开发者_Python百科itText) findViewById(R.id.Passtext);
    String username = input1.getText().toString();
    String password = input2.getText().toString();

If the login is successful, it will call the activity through intent.


If you are using ApiLevel >= 5 read about AccountManager.


I would recomend to use something like MD5 or SHA1 for hashing your password before storing.

A possible place to store could either be "preferences" or the sqlite DB (not such usefull for only one single dataset)


To save username & password in sharepref try

SharedPreferences.Editor editor=mPreferences.edit();
private SharedPreferences mPreferences;
mPreferences = getSharedPreferences("CurrentUser", MODE_PRIVATE);
editor.putString("UserName", username);
editor.putString("PassWord", password);
editor.commit();


You can use preferences or a file if you don't really care about security. You should encrypt the password if you're gonna store them though. See here for a better description of the options.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜