Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/189.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何保存android应用程序的登录详细信息?_Android_Login - Fatal编程技术网

如何保存android应用程序的登录详细信息?

如何保存android应用程序的登录详细信息?,android,login,Android,Login,我有一个android应用程序,需要用户名和密码才能登录。我需要将用户名和密码保存在手机本地或其他地方,以便在用户下次打开应用程序并自动登录应用程序时使用它们,而不显示登录屏幕 EditText input1 = (EditText) findViewById(R.id.usertext); EditText input2 = (EditText) findViewById(R.id.Passtext); String username = input1.getText(

我有一个android应用程序,需要用户名和密码才能登录。我需要将用户名和密码保存在手机本地或其他地方,以便在用户下次打开应用程序并自动登录应用程序时使用它们,而不显示登录屏幕

    EditText input1 = (EditText) findViewById(R.id.usertext);
    EditText input2 = (EditText) findViewById(R.id.Passtext);
    String username = input1.getText().toString();
    String password = input2.getText().toString();

如果登录成功,它将通过intent调用活动。

如果您不真正关心安全性,可以使用首选项或文件。如果你要储存密码,你应该加密密码。
有关选项的更好描述,请参阅。

我建议在存储之前使用类似MD5或SHA1的内容对密码进行哈希运算


如果您使用的是ApiLevel>=5,则可能的存储位置可以是“首选项”或sqlite DB(对于单个数据集不太有用)

请阅读。

要在sharepref中保存用户名和密码,请尝试

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

很好,不知道它存在:)根据Android文档“了解AccountManager不是加密服务或密钥链非常重要。它以纯文本形式存储帐户凭据,就像您传递它们一样。在大多数设备上,这并不是一个特别的问题,因为它将它们存储在一个只有root用户才能访问的数据库中。但在根设备上,任何有权访问该设备的人都可以读取凭据“这相当于在private SharedReference中以明文形式存储密码,我建议使用任何密钥生成md5,然后将其存储在private SharedReference或AccountManager中。这是一个非常糟糕的主意,因为任何具有根权限的人都可以访问它(现在很容易获得)。