I would like to ask how the automatic login function of the app is implemented and the user name and password are stored locally? I would like to ask how the automatic login function of the app is implemented and the user name and password are stored locally?
Reply content:
I would like to ask how the automatic login function of the app is implemented and the user name and password are stored locally?
Generally, you log on to the console first and get an authorized token. The client saves the token, which will be included in each request.
If the token has expired during the request, the app will redirect the user to the logon page and re-authorize the token.
Specifically, the implementation of token can be considered using jwt
private SharedPreferences sharedPreferences;private SharedPreferences.Editor editor;
Protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_login); sharedPreferences = getSharedPreferences ("config", MODE_PRIVATE); editor = sharedPreferences. edit (); // read the saved logon information String username = sharedPreferences when you open the app. getString ("username", ""); String password = sharedPreferences. getString ("password", ""); if (username! = "" & Password! = "") {Login (username, password); // login is the code you want to log on }}
When the logon button is clicked, the username and password content editor is obtained. putString ("username", username); editor. putString ("password", password); editor. commit () // when logging on, save the user name and password