简体   繁体   中英

Improving login/logout system

I have a login/logout system where by the user logs in either via facebook or our own mysql database.

When users successfully logins in the fullying is saved:

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("loggedIn", true);
editor.putString("email", EMAIL); 
editor.putString("password", PASSWORD);
editor.putInt("USERID",  Integer.parseInt((String) product.get("ProfileID")));
editor.commit(); 

And then I have a splash page which checks if the user is logged in:

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
boolean loggedin = settings.getBoolean("loggedIn", false);
if (loggedin) {
    Intent intent = new Intent(this, LoggedIn.class);
    startActivity(intent);
} else {
    Intent intent = new Intent(this, LogIn.class);
    startActivity(intent);
}

And then when a user logs out:

SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("loggedIn", false);
editor.putString("email", "");
editor.putString("password", "");
editor.commit();
db.clearLists();
db.clearProducts();
Intent intent = new Intent(v.getContext(), Splash.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP );
v.getContext().startActivity(intent);

This seems to work fine, ie the user logs out and is sent back to the login page and all their data has been cleared from the app.

However some users are reporting that if they close the app and come back to it they are actually still logged in. I can not replicate this and so wondering if anyone has any input on how to improve my login/out system to improve it and prevent this.

your code looks ok. But I suppose you can transfer your login to the sqlite db. save them to to db and retrieve login info from db. this is a quick dirty fix;)

最好在注销和登录时刷新共享首选项,然后检查是否存在共享首选项,然后以其他方式登录,将用户重定向到登录页面。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM