我正在尝试使用PHP和MySQLi为Android制作登录功能。但我不明白如何保持用户的登录状态?我看过一个简单的教程,其中有人使用SQLite来保存信息,但我不确定这是否是安全的方法。那么,我应该如何保存用户信息以保持其登录状态呢?
谢谢。
谢谢。
在Android中使用SharedPreferences
当您登录后,请使用它来存储数据
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0); // 0 - for private mode
Editor editor = pref.edit();
//on the login store the login
editor.putLong("key_name", "long value");
editor.commit();
pref.getString("key_name", "");
^
default value if the user is not loggedin
登出时清除数据
editor.remove("name");
editor.commit();
请参考这个链接了解更多相关的IT技术。
String masterKeyAlias = MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC);
SharedPreferences sharedPreferences = EncryptedSharedPreferences.create(
"secret_shared_prefs",
masterKeyAlias,
context,
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
);
// use the shared preferences and editor as you normally would
SharedPreferences.Editor editor = sharedPreferences.edit();
您也可以使用不可预测的密钥来使您的数据更加安全。