Questions about Automatic Logon

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.