How do I keep my login?

Asked 2 years ago, Updated 2 years ago, 134 views

I want to make sure that the login is maintained when the user logs in and out of a project in progress. What should I do?

After sending the ID password on Android, I check the login on php and deliver the session ID to Android again, but does Android have to save this session ID in Cookie?

Can't you just save it in a static variable instead of saving it in a cookie and deliver it together when there is another request? I wonder if this session ID must be included in the header and sent.

login

2022-09-22 15:20

1 Answers

A common way to keep a login is by Session&Cookies.
If you need it, there will be no problem with the operation if you assign it to the variable and send it to another request.

However, allocating to a variable means
When an app dies or memory is empty, the value of the variable may be initialized and the login may not be maintained, so additional actions such as saving it to a file will be necessary.

If you use php for the server side, it is likely that you are using a specific framework, such as CI or Laravel.
(I thought you wouldn't develop the server side yourself, to guess from the question.))

At first, I mentioned that the common way to maintain login is to keep it in session&cookies, but most of these frameworks already have login functionality implemented.

For example, you can assign a login (for example, "auth") filter to the route and set it up to require login, but if you use basic login retention techniques, you won't have much to set up.

As you said, if you save it through a variable and send it to a specific parameter on request, it is not the default rule, so it is inevitable to rewrite the filter or modify a lot.

It's not wrong, but it seems better to adopt general techniques to make it easier to work.

I will explain the login flow using Laravel that I usually use.

The framework recommends creating an item called password and remember token in the Users table.
When you log in to the app, you create a remember token.
This is cached (memory, ready, file cache, DB, etc.).
In response to the login action, it is dropped into the Set-Cookie header.
It's an order for the client to bake cookies.
The client then turns it into a cookie.
As for the next action, you can send the member talken cookie together like a normal browser.
I think that's probably the basic behavior of a typical Request object on Android.

However, if you turn off and turn on the device in this way, there may be cases where cookies fly depending on the Android device.
This requires several follow-up actions, such as storing the values in storage and then taking them out and cookies if necessary.

I hope it helps.


2022-09-22 15:20

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.